diff options
| author | Jan Krňávek <Jan.Krnavek@gmail.com> | 2021-03-13 19:08:16 +0100 |
|---|---|---|
| committer | Jan Krňávek <Jan.Krnavek@gmail.com> | 2021-03-13 19:08:16 +0100 |
| commit | c3fc7cdc5bd714f2fd7c45b54d27603509499ec0 (patch) | |
| tree | 4e7c4442ef05f21e6daee82f501cf8169a355fc7 | |
| parent | d1438fe7cb03045f357c4e9ac389e16cea3c018c (diff) | |
| download | perlweeklychallenge-club-c3fc7cdc5bd714f2fd7c45b54d27603509499ec0.tar.gz perlweeklychallenge-club-c3fc7cdc5bd714f2fd7c45b54d27603509499ec0.tar.bz2 perlweeklychallenge-club-c3fc7cdc5bd714f2fd7c45b54d27603509499ec0.zip | |
solutions week 103
| -rw-r--r-- | challenge-103/wambash/raku/ch-1.raku | 20 | ||||
| -rw-r--r-- | challenge-103/wambash/raku/ch-2.raku | 23 | ||||
| -rw-r--r-- | challenge-103/wambash/raku/playlist.csv | 7 |
3 files changed, 50 insertions, 0 deletions
diff --git a/challenge-103/wambash/raku/ch-1.raku b/challenge-103/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..e2ceabf5fb --- /dev/null +++ b/challenge-103/wambash/raku/ch-1.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + +constant @animal = < Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey Rooster Dog Pig >; +constant @element = <Yang Ying> RXR~ ' ' RXR~ <Wood Fire Earth Metal Water>; +constant @sexagenary-cycle = |@element xx 6 Z~ ' ' xx * Z~ |@animal xx 5; + +sub chinese-zodiac ( $year ) { + @sexagenary-cycle.[($year-4) mod 60]; +} + +multi MAIN (UInt $year ) { + say chinese-zodiac $year +} + +multi MAIN (Bool :$test! ) { + use Test; + is chinese-zodiac(2017), 'Ying Fire Rooster'; + is chinese-zodiac(1938), 'Yang Earth Tiger'; + done-testing; +} diff --git a/challenge-103/wambash/raku/ch-2.raku b/challenge-103/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..5f89e805e5 --- /dev/null +++ b/challenge-103/wambash/raku/ch-2.raku @@ -0,0 +1,23 @@ +#!/usr/bin/env raku + +sub what's-playing ( $start-time, $current-time = now, $file = 'playlist.csv' ) { + my (@time, @name) := [Z] $file.IO.lines.map: {.split: ',', 2}; + my @time-to = [\+] |@time.map: * / 1000; + my $time-in-playlist = ($current-time - $start-time) % @time-to.tail; + + @time-to.first: * > $time-in-playlist,:k + andthen @name[$_] => ($time-in-playlist - (0,|@time-to)[$_]).polymod(60, 60).reverse.fmt('%02d',':'); +} + +multi MAIN (Bool :$test!) { + use Test; + is what's-playing( 1606134123, 1614591276, ).value, '00:10:24'; + like what's-playing( 1606134123, 1614591276, 'playlist.csv').key, /:s Episode 1/; + is what's-playing( 1606134123, 1694591276, ).value, '00:08:46'; + like what's-playing( 1606134123, 1694591276, ).key, /:s Episode 6/; + done-testing; +} + +multi MAIN ( $start-time, $current-time = now, $file = 'playlist.csv' ) { + say what's-playing $start-time, $current-time, $file +} diff --git a/challenge-103/wambash/raku/playlist.csv b/challenge-103/wambash/raku/playlist.csv new file mode 100644 index 0000000000..9428b93004 --- /dev/null +++ b/challenge-103/wambash/raku/playlist.csv @@ -0,0 +1,7 @@ +1709363,"Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)" +1723781,"Les Miserables Episode 2: Javert (broadcast date: 1937-07-30)" +1723781,"Les Miserables Episode 3: The Trial (broadcast date: 1937-08-06)" +1678356,"Les Miserables Episode 4: Cosette (broadcast date: 1937-08-13)" +1646043,"Les Miserables Episode 5: The Grave (broadcast date: 1937-08-20)" +1714640,"Les Miserables Episode 6: The Barricade (broadcast date: 1937-08-27)" +1714640,"Les Miserables Episode 7: Conclusion (broadcast date: 1937-09-03)" |
