aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-03-08 08:57:38 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-03-08 08:57:38 -0500
commit2b73d28287ba8cebf9c8cfcae8819c178718347e (patch)
treee1bcf27d193c93bdf8817ac5d7af3e7c218b1a7c
parent4ca90aa3b8a785fe2e2d0b64524c42c4015f11bf (diff)
downloadperlweeklychallenge-club-2b73d28287ba8cebf9c8cfcae8819c178718347e.tar.gz
perlweeklychallenge-club-2b73d28287ba8cebf9c8cfcae8819c178718347e.tar.bz2
perlweeklychallenge-club-2b73d28287ba8cebf9c8cfcae8819c178718347e.zip
1st commit on 103_raku
-rw-r--r--challenge-103/stuart-little/README1
-rwxr-xr-xchallenge-103/stuart-little/raku/ch-1.p618
-rwxr-xr-xchallenge-103/stuart-little/raku/ch-2.p637
3 files changed, 56 insertions, 0 deletions
diff --git a/challenge-103/stuart-little/README b/challenge-103/stuart-little/README
new file mode 100644
index 0000000000..78439907de
--- /dev/null
+++ b/challenge-103/stuart-little/README
@@ -0,0 +1 @@
+Solutions by Stuart Little
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|;