From c3fc7cdc5bd714f2fd7c45b54d27603509499ec0 Mon Sep 17 00:00:00 2001 From: Jan Krňávek Date: Sat, 13 Mar 2021 19:08:16 +0100 Subject: solutions week 103 --- challenge-103/wambash/raku/ch-1.raku | 20 ++++++++++++++++++++ challenge-103/wambash/raku/ch-2.raku | 23 +++++++++++++++++++++++ challenge-103/wambash/raku/playlist.csv | 7 +++++++ 3 files changed, 50 insertions(+) create mode 100644 challenge-103/wambash/raku/ch-1.raku create mode 100644 challenge-103/wambash/raku/ch-2.raku create mode 100644 challenge-103/wambash/raku/playlist.csv 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 = RXR~ ' ' RXR~ ; +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)" -- cgit