diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-03-14 01:09:43 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-14 01:09:43 +0000 |
| commit | 80e8dac106d9b9a5c52dc85ff883a5ce97a86243 (patch) | |
| tree | 65ef042a8b02ed3e9665823acffcde53c760917a | |
| parent | d1438fe7cb03045f357c4e9ac389e16cea3c018c (diff) | |
| parent | bc5865a51f272795c3a0a1ee1099f4c0fd661b69 (diff) | |
| download | perlweeklychallenge-club-80e8dac106d9b9a5c52dc85ff883a5ce97a86243.tar.gz perlweeklychallenge-club-80e8dac106d9b9a5c52dc85ff883a5ce97a86243.tar.bz2 perlweeklychallenge-club-80e8dac106d9b9a5c52dc85ff883a5ce97a86243.zip | |
Merge pull request #3711 from mimosinnet/branch-for-challenge-103
Solution for challenge 103
| -rw-r--r-- | challenge-103/mimosinnet/raku/ch-1.raku | 38 | ||||
| -rw-r--r-- | challenge-103/mimosinnet/raku/ch-2.raku | 82 | ||||
| -rw-r--r-- | challenge-103/mimosinnet/raku/filelist.csv | 7 |
3 files changed, 127 insertions, 0 deletions
diff --git a/challenge-103/mimosinnet/raku/ch-1.raku b/challenge-103/mimosinnet/raku/ch-1.raku new file mode 100644 index 0000000000..942fc8f072 --- /dev/null +++ b/challenge-103/mimosinnet/raku/ch-1.raku @@ -0,0 +1,38 @@ +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-103/ + +class ChineseZodiac { + has $.year; + has @!animals = <Monkey Rooster Dog Pig Rat Ox Tiger Rabbit Dragon Snake Horse Goat>; + has @!elements = <Metal Water Wood Fire Earth>; + + + method chinese-zodiac() { + return sprintf('%s %s', @!elements[ floor( $!year / 2 % 5 ) ], @!animals[ $!year % 12 ]); + } +} + +multi sub MAIN( $year ) { + say 'Input: ',$year; + say sprintf("Output: %s\n",ChineseZodiac.new( year => $year ).chinese-zodiac); +} + +multi sub MAIN( 'challenge' ) { + my @challenge = < 2017 1938 >; + + for @challenge -> $a { + MAIN($a); + } +} + +multi sub MAIN( 'test' ) is hidden-from-USAGE { + use Test; + + my %test = + 2017, 'Fire Rooster', + 1938, 'Earth Tiger' + ; + + for %test.keys -> $a { + is ChineseZodiac.new( year => $a ).chinese-zodiac, %test{$a}; + } +} diff --git a/challenge-103/mimosinnet/raku/ch-2.raku b/challenge-103/mimosinnet/raku/ch-2.raku new file mode 100644 index 0000000000..516e8102e4 --- /dev/null +++ b/challenge-103/mimosinnet/raku/ch-2.raku @@ -0,0 +1,82 @@ +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-103/ + +class Time { + has $.second; + + method time() { + my ($hour, $minute) = (0,0); + if $!second >= 3600 { + $hour = $!second div 3600; + $!second = $!second % 3600; + } + if $!second >= 60 { + $minute = $!second div 60; + $!second = $!second % 60; + } + return sprintf('%02d:%02d:%02d',$hour,$minute,$!second); + } +} + +class Movies { + + has $.starttime; + has $.currenttime; + has $.filelist; + has @!show; # ( [ time, show ] ) + has $!position; + has $.time-playlist; + + submethod TWEAK { + # miliseconds -> seconds + $!filelist.IO.linesĀ».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b ) }); + $!position = ( $!currenttime - $!starttime ) % (@!show[*;0].sum/1000); + $!time-playlist = Time.new( second => $!position.Int ).time; + } + + method what-show() { + my ($time, $show); + for @!show[*;0] -> $show-time { + $time += $show-time; + return @!show[$show++;1] if $time > $!position; + } + } +} + +multi sub MAIN( $start-time, $current-time, $filelist ) { + my $show = Movies.new( starttime => $start-time, currenttime => $current-time, filelist => $filelist); + say "Input: 3 command line parameters: start time, current time, file name\n"; + say '# starttime : ',$start-time; + say '# currenttime: ',$current-time; + say sprintf("# %s\n",$filelist); + say "Output:"; + say $show.what-show; + say $show.time-playlist; +} + +multi sub MAIN( 'challenge' ) { + + my $a = '1606134123'; + my $b = '1614591276'; + my $c = 'filelist.csv'; + + MAIN($a, $b, $c); +} + +multi sub MAIN( 'test' ) is hidden-from-USAGE { + use Test; + + is Time.new( second => 59).time, '00:00:59'; + is Time.new( second => 61).time, '00:01:01'; + is Time.new( second => 3661).time,'01:01:01'; + + my $a = '1606134123'; + my $b = '1614591276'; + my $c = 'filelist.csv'; + my $d = '"Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)"'; + my $e = '00:10:24'; + + my $mv = Movies.new( starttime => $a, currenttime => $b, filelist => $c); + is $mv.what-show,$d; + is $mv.time-playlist,$e; + +} diff --git a/challenge-103/mimosinnet/raku/filelist.csv b/challenge-103/mimosinnet/raku/filelist.csv new file mode 100644 index 0000000000..9428b93004 --- /dev/null +++ b/challenge-103/mimosinnet/raku/filelist.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)" |
