diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-08-21 21:46:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-21 21:46:18 +0100 |
| commit | 501bc8e40e7d055e851c0fa705b2091bae8e7c91 (patch) | |
| tree | c19f2f368c2135af26454dd6b519fbbd323e1c2f | |
| parent | b3640e8b823f5b4633139b2e1fd0ef0867f50dc4 (diff) | |
| parent | 90716292dd61106377b2cc8253aed12e1d875c83 (diff) | |
| download | perlweeklychallenge-club-501bc8e40e7d055e851c0fa705b2091bae8e7c91.tar.gz perlweeklychallenge-club-501bc8e40e7d055e851c0fa705b2091bae8e7c91.tar.bz2 perlweeklychallenge-club-501bc8e40e7d055e851c0fa705b2091bae8e7c91.zip | |
Merge pull request #6638 from arnesom/branch-for-challenge-178
Arne Sommer
| -rw-r--r-- | challenge-178/arne-sommer/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-178/arne-sommer/raku/business-date | 26 | ||||
| -rwxr-xr-x | challenge-178/arne-sommer/raku/business-date-int | 22 | ||||
| -rwxr-xr-x | challenge-178/arne-sommer/raku/ch-1.raku | 30 | ||||
| -rwxr-xr-x | challenge-178/arne-sommer/raku/ch-2.raku | 26 | ||||
| -rwxr-xr-x | challenge-178/arne-sommer/raku/quater-imaginary-base | 30 | ||||
| -rwxr-xr-x | challenge-178/arne-sommer/raku/quater-imaginary-base-stubbed | 26 |
7 files changed, 161 insertions, 0 deletions
diff --git a/challenge-178/arne-sommer/blog.txt b/challenge-178/arne-sommer/blog.txt new file mode 100644 index 0000000000..458936562d --- /dev/null +++ b/challenge-178/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/imaginary-date.html diff --git a/challenge-178/arne-sommer/raku/business-date b/challenge-178/arne-sommer/raku/business-date new file mode 100755 index 0000000000..a3efc427d9 --- /dev/null +++ b/challenge-178/arne-sommer/raku/business-date @@ -0,0 +1,26 @@ +#! /usr/bin/env raku + +unit sub MAIN (Str $timestamp, Str $duration); + +my ($duration-hour, $duration-min) = $duration.split(".")>>.Int; + +$duration-min = $duration-min ?? $duration-min * 6 !! 0; + +my ($ymd, $hm) = $timestamp.split(" "); + +my $dt = DateTime.new($ymd ~ "T" ~ $hm ~ ":00"); + +die "Only 09:00-18:00 allowed" if $dt.hour < 9 || $dt.hour == 18 && $dt.minute || $dt.hour > 18; + +$dt.=later([days => $duration-hour div 9, hours => $duration-hour % 9, minutes => $duration-min]); + +if $dt.hour < 9 +{ + $dt.=later(hours => 9); +} +elsif $dt.hour == 18 && $dt.minute || $dt.hour > 18 +{ + $dt.=later(hours => 15); +} + +say $dt.yyyy-mm-dd ~ " " ~ $dt.hh-mm-ss.substr(0,5); diff --git a/challenge-178/arne-sommer/raku/business-date-int b/challenge-178/arne-sommer/raku/business-date-int new file mode 100755 index 0000000000..082c0a821b --- /dev/null +++ b/challenge-178/arne-sommer/raku/business-date-int @@ -0,0 +1,22 @@ +#! /usr/bin/env raku + +unit sub MAIN (Str $timestamp, UInt $duration); + +my ($ymd, $hm) = $timestamp.split(" "); + +my $dt = DateTime.new($ymd ~ "T" ~ $hm ~ ":00"); + +die "Only 09:00-18:00 allowed" if $dt.hour < 9 || $dt.hour == 18 && $dt.minute || $dt.hour > 18; + +$dt.=later([days => $duration div 9, hours => $duration % 9]); + +if $dt.hour < 9 +{ + $dt.=later(hours => 9); +} +elsif $dt.hour == 18 && $dt.minute || $dt.hour > 18 +{ + $dt.=later(hours => 15); +} + +say $dt.yyyy-mm-dd ~ " " ~ $dt.hh-mm-ss.substr(0,5); diff --git a/challenge-178/arne-sommer/raku/ch-1.raku b/challenge-178/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..58e41c8350 --- /dev/null +++ b/challenge-178/arne-sommer/raku/ch-1.raku @@ -0,0 +1,30 @@ +#! /usr/bin/env raku + +unit sub MAIN (:b(:$base10), :q(:$quater)); + +die "Specify one of 'base10' or 'quater'" unless one($base10, $quater); + +say decimal-to-quater($base10) if $base10; +say quater-to-decimal($quater) if $quater; + +sub quater-to-decimal ($number) +{ + my $decimal = 0; + my $length = $number.chars; + + for ^$length -> $d + { + $decimal += $number.substr($d, 1) * (2i ** --$length); + } + + return $decimal ~~ /(.*)\+0i$/ ?? $decimal.Int !! $decimal; +} + +sub decimal-to-quater ($number) +{ + die "Positive integers only, at this time" unless $number ~~ /^\d+$/; + + constant Schroeppel4 = 0xCCCCCCCC; + + return ( ($number + Schroeppel4 ) +^ Schroeppel4 ).base(4); +} diff --git a/challenge-178/arne-sommer/raku/ch-2.raku b/challenge-178/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..a3efc427d9 --- /dev/null +++ b/challenge-178/arne-sommer/raku/ch-2.raku @@ -0,0 +1,26 @@ +#! /usr/bin/env raku + +unit sub MAIN (Str $timestamp, Str $duration); + +my ($duration-hour, $duration-min) = $duration.split(".")>>.Int; + +$duration-min = $duration-min ?? $duration-min * 6 !! 0; + +my ($ymd, $hm) = $timestamp.split(" "); + +my $dt = DateTime.new($ymd ~ "T" ~ $hm ~ ":00"); + +die "Only 09:00-18:00 allowed" if $dt.hour < 9 || $dt.hour == 18 && $dt.minute || $dt.hour > 18; + +$dt.=later([days => $duration-hour div 9, hours => $duration-hour % 9, minutes => $duration-min]); + +if $dt.hour < 9 +{ + $dt.=later(hours => 9); +} +elsif $dt.hour == 18 && $dt.minute || $dt.hour > 18 +{ + $dt.=later(hours => 15); +} + +say $dt.yyyy-mm-dd ~ " " ~ $dt.hh-mm-ss.substr(0,5); diff --git a/challenge-178/arne-sommer/raku/quater-imaginary-base b/challenge-178/arne-sommer/raku/quater-imaginary-base new file mode 100755 index 0000000000..58e41c8350 --- /dev/null +++ b/challenge-178/arne-sommer/raku/quater-imaginary-base @@ -0,0 +1,30 @@ +#! /usr/bin/env raku + +unit sub MAIN (:b(:$base10), :q(:$quater)); + +die "Specify one of 'base10' or 'quater'" unless one($base10, $quater); + +say decimal-to-quater($base10) if $base10; +say quater-to-decimal($quater) if $quater; + +sub quater-to-decimal ($number) +{ + my $decimal = 0; + my $length = $number.chars; + + for ^$length -> $d + { + $decimal += $number.substr($d, 1) * (2i ** --$length); + } + + return $decimal ~~ /(.*)\+0i$/ ?? $decimal.Int !! $decimal; +} + +sub decimal-to-quater ($number) +{ + die "Positive integers only, at this time" unless $number ~~ /^\d+$/; + + constant Schroeppel4 = 0xCCCCCCCC; + + return ( ($number + Schroeppel4 ) +^ Schroeppel4 ).base(4); +} diff --git a/challenge-178/arne-sommer/raku/quater-imaginary-base-stubbed b/challenge-178/arne-sommer/raku/quater-imaginary-base-stubbed new file mode 100755 index 0000000000..9d7b479cb7 --- /dev/null +++ b/challenge-178/arne-sommer/raku/quater-imaginary-base-stubbed @@ -0,0 +1,26 @@ +#! /usr/bin/env raku + +unit sub MAIN (:b(:$base10), :q(:$quater)); + +die "Specify one of 'base10' or 'quater'" unless one($base10, $quater); + +say decimal-to-quater($base10) if $base10; +say quater-to-decimal($quater) if $quater; + +sub quater-to-decimal ($number) +{ + my $decimal = 0; + my $length = $number.chars; + + for ^$length -> $d + { + $decimal += $number.substr($d, 1) * (2i ** --$length); + } + + return $decimal ~~ /(.*)\+0i$/ ?? $decimal.Int !! $decimal; +} + +sub decimal-to-quater ($number) +{ + !!! "Not implemented yet" +} |
