aboutsummaryrefslogtreecommitdiff
path: root/challenge-103
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-03-08 14:25:44 +0000
committerGitHub <noreply@github.com>2021-03-08 14:25:44 +0000
commit13b740ef05c26258ae119216b03ac73496bf3a5a (patch)
tree5b90a5ae00fa8f27c543adb2707b77dda5b6aa6f /challenge-103
parentcc5995af658ed34e4dd2c9eefb070ff1e52506f6 (diff)
parent2b73d28287ba8cebf9c8cfcae8819c178718347e (diff)
downloadperlweeklychallenge-club-13b740ef05c26258ae119216b03ac73496bf3a5a.tar.gz
perlweeklychallenge-club-13b740ef05c26258ae119216b03ac73496bf3a5a.tar.bz2
perlweeklychallenge-club-13b740ef05c26258ae119216b03ac73496bf3a5a.zip
Merge pull request #3689 from stuart-little/stuart-little_103_raku
1st commit on 103_raku
Diffstat (limited to 'challenge-103')
-rwxr-xr-xchallenge-103/stuart-little/raku/ch-1.p618
-rwxr-xr-xchallenge-103/stuart-little/raku/ch-2.p637
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-103/stuart-little/raku/ch-1.p6 b/challenge-103/stuart-little/raku/ch-1.p6
new file mode 100755
index 0000000000..e5dcc72db1
--- /dev/null
+++ b/challenge-103/stuart-little/raku/ch-1.p6
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl6
+use v6;
+
+# run <script> <year>
+
+sub animal(@animals,$year,$base) {
+ @animals[($year - $base) % @animals.elems]
+}
+
+sub elt(@elts,$year,$base) {
+ @elts[(($year - $base) % (2*@elts.elems)) div 2]
+}
+
+my @animals=<Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey Rooster Dog Pig>;
+my @elts=<Wood Fire Earth Metal Water>;
+my $year=@*ARGS[0].Int;
+
+say qq|{elt(@elts,$year,1924)} {animal(@animals,$year,1924)}|;
diff --git a/challenge-103/stuart-little/raku/ch-2.p6 b/challenge-103/stuart-little/raku/ch-2.p6
new file mode 100755
index 0000000000..7cec43ecdc
--- /dev/null
+++ b/challenge-103/stuart-little/raku/ch-2.p6
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl6
+use v6;
+
+# run <script> <start time as unix epoch> <current time as unix epoch> <path-to-csv>
+
+sub fromCSV($path) {
+ $path.IO.lines.map(*.split(',')).map( -> ($t,$f) {$t.Int,$f})
+}
+
+sub totPlayTime(@files) {
+ @files.map(*.head).sum
+}
+
+sub cvToTime($millisecs) {
+ my $totSecs=($millisecs/1000).round;
+ my $s = $totSecs % 60;
+ my $m = ($totSecs div 60) % 60;
+ my $h = ($totSecs - $m*60 - $s) div 60**2;
+ return ($h,$m,$s);
+}
+
+sub whichPlaying($tdiff,@files) {
+ ($tdiff <= @files[0].head) && return @files[0].tail;
+ return whichPlaying($tdiff - @files[0].head, @files[1..*]);
+}
+
+sub wherePlaying($tdiff,@files) {
+ cvToTime($tdiff % @files.&totPlayTime)
+}
+
+my @files = fromCSV(@*ARGS[2]);
+my $tdiff = (@*ARGS[1].Int-@*ARGS[0].Int)*1000 % @files.&totPlayTime;
+
+my ($h,$m,$s) = wherePlaying($tdiff,@files);
+my $playingFile = whichPlaying($tdiff,@files);
+
+say qq|\nPlaying: $playingFile\n\nAt: $h:$m:$s|;