aboutsummaryrefslogtreecommitdiff
path: root/challenge-102
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-03-08 14:12:57 +0000
committerGitHub <noreply@github.com>2021-03-08 14:12:57 +0000
commit835c7468cff51181a687fa06d34cea7c215bc9e7 (patch)
tree28c636a248000ab5e2537b2b3c00ce118d6af74e /challenge-102
parent59e097feaa200e6993eb4bef17c83a007b30fdb2 (diff)
parent3d8e84a522d381da7288e34466ef75a1bc33bcec (diff)
downloadperlweeklychallenge-club-835c7468cff51181a687fa06d34cea7c215bc9e7.tar.gz
perlweeklychallenge-club-835c7468cff51181a687fa06d34cea7c215bc9e7.tar.bz2
perlweeklychallenge-club-835c7468cff51181a687fa06d34cea7c215bc9e7.zip
Merge pull request #3688 from fluca1978/pwc103
Pwc103
Diffstat (limited to 'challenge-102')
-rw-r--r--challenge-102/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-102/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-102/luca-ferrari/raku/ch-1.p635
-rw-r--r--challenge-102/luca-ferrari/raku/ch-2.p629
-rw-r--r--challenge-102/luca-ferrari/raku/filelist.csv7
5 files changed, 73 insertions, 0 deletions
diff --git a/challenge-102/luca-ferrari/blog-1.txt b/challenge-102/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..bd1b918530
--- /dev/null
+++ b/challenge-102/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/03/08/PerlWeeklyChallenge103.html#task1
diff --git a/challenge-102/luca-ferrari/blog-2.txt b/challenge-102/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..80df7ccc0f
--- /dev/null
+++ b/challenge-102/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/03/08/PerlWeeklyChallenge103.html#task2
diff --git a/challenge-102/luca-ferrari/raku/ch-1.p6 b/challenge-102/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..e4548522fc
--- /dev/null
+++ b/challenge-102/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,35 @@
+#!raku
+
+
+
+class ChineseCalendar {
+ has DateTime $!now;
+ has Str @!animals;
+ has Str @!elements;
+
+ submethod BUILD( :$year = Nil ) {
+ @!animals = qw/ Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey Rooster Dog Pig /;
+ @!elements = qw/ Wood Fire Earth Metal Water /;
+ $!now = $year ?? DateTime.new: year => $year !! DateTime.now;
+ }
+
+ method element() {
+ return @!elements[ ( $!now.year - 4 ) % 10 / 2 ];
+ }
+
+ method animal() {
+ return @!animals[ ( $!now.year - 4 ) % 12 ];
+ }
+}
+
+
+multi sub MAIN( Int $year where { $year > 1900 } ) {
+ my $cc = ChineseCalendar.new: year => $year;
+
+ say "Year $year is %s %s".sprintf:
+ $cc.element, $cc.animal;
+}
+
+multi sub MAIN() {
+ MAIN( DateTime.now.year );
+}
diff --git a/challenge-102/luca-ferrari/raku/ch-2.p6 b/challenge-102/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..9ea6e731df
--- /dev/null
+++ b/challenge-102/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,29 @@
+#!raku
+
+
+sub MAIN( Int $start-ms where { $start-ms > 0 },
+ Int $now-ms where { $now-ms >= $start-ms },
+ Str $filename ) {
+
+ # lookup file name and tracks
+ my @tracks;
+ for $filename.IO.lines {
+ my ( $ms, $track ) = .split: ',';
+ @tracks.push: { time => $ms,
+ track => $track };
+ }
+
+ # try to reach the end of the time
+ my $diff = $now-ms - $start-ms;
+ my $last-track = 0;
+ while ( $diff > 0 ) {
+ $last-track = 0;
+ for @tracks.kv -> $index, $track {
+ $diff -= $track< time >;
+ last if ( $diff <= 0 );
+ $last-track = $index;
+ }
+ }
+
+ "Now playing { @tracks[ $last-track ]<track> } ".say;
+}
diff --git a/challenge-102/luca-ferrari/raku/filelist.csv b/challenge-102/luca-ferrari/raku/filelist.csv
new file mode 100644
index 0000000000..9428b93004
--- /dev/null
+++ b/challenge-102/luca-ferrari/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)"