aboutsummaryrefslogtreecommitdiff
path: root/challenge-100/lance-wicks
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-100/lance-wicks')
-rw-r--r--challenge-100/lance-wicks/elm/elm.json28
-rw-r--r--challenge-100/lance-wicks/elm/src/Fun.elm69
-rw-r--r--challenge-100/lance-wicks/elm/tests/Example.elm40
-rw-r--r--challenge-100/lance-wicks/perl/ch-1.pl11
-rw-r--r--challenge-100/lance-wicks/perl/lib/Fun.pm35
-rw-r--r--challenge-100/lance-wicks/perl/t/00-fun.t10
6 files changed, 193 insertions, 0 deletions
diff --git a/challenge-100/lance-wicks/elm/elm.json b/challenge-100/lance-wicks/elm/elm.json
new file mode 100644
index 0000000000..7468f5e5cd
--- /dev/null
+++ b/challenge-100/lance-wicks/elm/elm.json
@@ -0,0 +1,28 @@
+{
+ "type": "application",
+ "source-directories": [
+ "src"
+ ],
+ "elm-version": "0.19.1",
+ "dependencies": {
+ "direct": {
+ "elm/browser": "1.0.2",
+ "elm/core": "1.0.5",
+ "elm/html": "1.0.0"
+ },
+ "indirect": {
+ "elm/json": "1.1.3",
+ "elm/time": "1.0.0",
+ "elm/url": "1.0.0",
+ "elm/virtual-dom": "1.0.2"
+ }
+ },
+ "test-dependencies": {
+ "direct": {
+ "elm-explorations/test": "1.2.2"
+ },
+ "indirect": {
+ "elm/random": "1.0.0"
+ }
+ }
+}
diff --git a/challenge-100/lance-wicks/elm/src/Fun.elm b/challenge-100/lance-wicks/elm/src/Fun.elm
new file mode 100644
index 0000000000..2f9775c70b
--- /dev/null
+++ b/challenge-100/lance-wicks/elm/src/Fun.elm
@@ -0,0 +1,69 @@
+module Fun exposing (convert)
+
+
+convert : String -> String
+convert time =
+ if String.contains "am" time then
+ String.slice 0 5 time
+
+ else if String.contains "pm" time then
+ let
+ hourMin =
+ String.split ":" time
+ in
+ case List.head hourMin of
+ Just a ->
+ let
+ hour =
+ String.toInt a
+ in
+ case hour of
+ Just h ->
+ let
+ hx =
+ h + 12
+ in
+ String.fromInt hx ++ String.slice 2 5 time
+
+ Nothing ->
+ ""
+
+ Nothing ->
+ ""
+
+ else
+ let
+ hourMin =
+ String.split ":" time
+ in
+ case List.head hourMin of
+ Just a ->
+ let
+ hour =
+ String.toInt a
+ in
+ case hour of
+ Just h ->
+ if h > 12 then
+ let
+ hx =
+ h - 12
+ in
+ let
+ hourStr =
+ String.fromInt hx
+ in
+ if String.length hourStr > 1 then
+ hourStr ++ String.slice 2 5 time ++ "pm"
+
+ else
+ "0" ++ hourStr ++ String.slice 2 5 time ++ "pm"
+
+ else
+ String.slice 0 5 time ++ "am"
+
+ Nothing ->
+ ""
+
+ Nothing ->
+ ""
diff --git a/challenge-100/lance-wicks/elm/tests/Example.elm b/challenge-100/lance-wicks/elm/tests/Example.elm
new file mode 100644
index 0000000000..64c70d1337
--- /dev/null
+++ b/challenge-100/lance-wicks/elm/tests/Example.elm
@@ -0,0 +1,40 @@
+module Example exposing (..)
+
+import Expect exposing (Expectation)
+import Fun exposing (convert)
+import Fuzz exposing (Fuzzer, int, list, string)
+import Test exposing (..)
+
+
+suite : Test
+suite =
+ describe "Fun"
+ [ test "convert 07:15" <|
+ \_ ->
+ let
+ got =
+ convert "07:15"
+ in
+ Expect.equal got "07:15am"
+ , test "convert 05:15pm" <|
+ \_ ->
+ let
+ got =
+ convert "05:15 pm"
+ in
+ Expect.equal got "17:15"
+ , test "convert 19:15" <|
+ \_ ->
+ let
+ got =
+ convert "19:15"
+ in
+ Expect.equal got "07:15pm"
+ , test "convert 09:15" <|
+ \_ ->
+ let
+ got =
+ convert "09:15 am"
+ in
+ Expect.equal got "09:15"
+ ]
diff --git a/challenge-100/lance-wicks/perl/ch-1.pl b/challenge-100/lance-wicks/perl/ch-1.pl
new file mode 100644
index 0000000000..78310d45ab
--- /dev/null
+++ b/challenge-100/lance-wicks/perl/ch-1.pl
@@ -0,0 +1,11 @@
+use strict;
+use warnings;
+
+use lib './lib';
+use Fun;
+
+my $fun = Fun->new;
+
+print $fun->convert($ARGV[0]);
+print "\n";
+
diff --git a/challenge-100/lance-wicks/perl/lib/Fun.pm b/challenge-100/lance-wicks/perl/lib/Fun.pm
new file mode 100644
index 0000000000..d1e1088614
--- /dev/null
+++ b/challenge-100/lance-wicks/perl/lib/Fun.pm
@@ -0,0 +1,35 @@
+package Fun;
+
+use Moo;
+
+sub convert {
+ my ( $self, $time ) = @_;
+
+ if ( $time =~ m/([ap]m)/ ) {
+ my $am_pm = $1;
+
+ $time =~ m/^(\d+):(\d+)/;
+ my $hours = $1;
+ my $minutes = $2;
+
+ if ( $am_pm eq 'pm' ) {
+ $hours += 12;
+ }
+ return "$hours:$minutes";
+ }
+ else {
+ $time =~ m/^(\d+):(\d+)/;
+ my $hours = $1;
+ my $minutes = $2;
+
+ if ( $hours > 12 ) {
+ $hours -= 12;
+ return sprintf( "%02d", $hours ) . ":$minutes" . 'pm';
+ }
+ else {
+ return sprintf( "%02d", $hours ) . ":$minutes" . 'am';
+ }
+ }
+}
+
+1;
diff --git a/challenge-100/lance-wicks/perl/t/00-fun.t b/challenge-100/lance-wicks/perl/t/00-fun.t
new file mode 100644
index 0000000000..8cba91420a
--- /dev/null
+++ b/challenge-100/lance-wicks/perl/t/00-fun.t
@@ -0,0 +1,10 @@
+use Test2::V0 -target => "Fun";
+
+is $CLASS->convert("05:15 pm"), '17:15', 'Example 1-1';
+is $CLASS->convert("05:15pm"), '17:15', 'Example 1-2';
+
+is $CLASS->convert("19:15"), '07:15pm', 'Example 2-1';
+
+is $CLASS->convert("09:15"), '09:15am', '24hr AM';
+
+done_testing;