aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-08-30 23:36:16 +0100
committerGitHub <noreply@github.com>2021-08-30 23:36:16 +0100
commitb2aba2fca704d5f14908c941c152510e676e553f (patch)
tree939ff19c25afc906162538d0d107f559e2639c0e
parentc778b5d4e001fd074f4f0e2cf3ca0ed873e17afe (diff)
parentf6d2eb07c262a9d95eadb566399a090eed9c6d83 (diff)
downloadperlweeklychallenge-club-b2aba2fca704d5f14908c941c152510e676e553f.tar.gz
perlweeklychallenge-club-b2aba2fca704d5f14908c941c152510e676e553f.tar.bz2
perlweeklychallenge-club-b2aba2fca704d5f14908c941c152510e676e553f.zip
Merge pull request #4818 from fluca1978/pwc128
Pwc128
-rw-r--r--challenge-128/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-128/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-128/luca-ferrari/raku/ch-1.p658
-rw-r--r--challenge-128/luca-ferrari/raku/ch-2.p644
4 files changed, 104 insertions, 0 deletions
diff --git a/challenge-128/luca-ferrari/blog-1.txt b/challenge-128/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..e224f47754
--- /dev/null
+++ b/challenge-128/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/08/30/PerlWeeklyChallenge128.html#task1
diff --git a/challenge-128/luca-ferrari/blog-2.txt b/challenge-128/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..443735006c
--- /dev/null
+++ b/challenge-128/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/08/30/PerlWeeklyChallenge128.html#task2
diff --git a/challenge-128/luca-ferrari/raku/ch-1.p6 b/challenge-128/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..9294247d68
--- /dev/null
+++ b/challenge-128/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,58 @@
+#!raku
+
+sub MAIN() {
+ my @matrix = [ 1 ,0, 0, 0, 1, 0 ],
+ [ 1 ,1, 0, 0, 0, 1 ],
+ [ 1, 0, 0, 0, 0, 0 ];
+
+ my @zeroes;
+
+ for 0 ..^ @matrix.elems -> $current-row {
+ for 0 ..^ @matrix[ $current-row ].elems -> $current-column {
+ my $zeroes-count = 0;
+ my $column = $current-column;
+ my $previous-column = $current-column;
+ while ( $column < @matrix[ $current-row ].elems && $column - $previous-column <= 1 ) {
+ $zeroes-count++ if @matrix[ $current-row ][ $column ] == 0;
+ last if @matrix[ $current-row ][ $column ] != 0;
+ $previous-column = $column++;
+ }
+
+ @zeroes[ $current-row ][ $current-column ] = $zeroes-count;
+ }
+ }
+
+
+ my $rows = 0;
+ my $cols = 0;
+ my @sub-matrix;
+ my $max = 0;
+ for 0 ..^ @zeroes.elems -> $current-row {
+ for 0 ..^ @zeroes[ $current-row ].elems -> $current-column {
+ next if @zeroes[ $current-row ][ $current-column ] == 0;
+ $cols = @zeroes[ $current-row ][ $current-column ];
+ $rows = 1;
+
+
+ for $current-row + 1 ..^ @zeroes.elems -> $next-row {
+ $rows = 0 and last if @zeroes[ $next-row ][ $current-column ] == 0;
+ $rows++ if @zeroes[ $next-row ][ $current-column ] != 0;
+ $cols = min( $cols, @zeroes[ $next-row ][ $current-column ] );
+ }
+
+
+ $max = $rows * $cols and @sub-matrix = () if $rows * $cols > $max;
+ @sub-matrix.push: [ $rows * $cols, $current-row, $current-column, $current-row + $rows - 1, $current-column + $cols - 1 ] if $rows * $cols > 0 && $rows * $cols >= $max;
+
+
+
+
+ }
+ }
+
+ "{ $_[ 0 ] } zeroes starting from <{ $_[ 1 ] }, { $_[ 2 ]}> to <{ $_[ 3 ] }, { $_[ 4 ]}>".say for @sub-matrix;
+
+
+
+
+}
diff --git a/challenge-128/luca-ferrari/raku/ch-2.p6 b/challenge-128/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..8fb549c3ba
--- /dev/null
+++ b/challenge-128/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,44 @@
+#!raku
+
+
+class Train {
+ has Int $.hour-arrival;
+ has Int $.hour-departure;
+ has Int $.minute-arrival;
+ has Int $.minute-departure;
+
+
+ submethod BUILD( Str :$arrival, Str :$departure ) {
+ $arrival ~~ / (\d+) ':' (\d+) /;
+ ( $!hour-arrival, $!minute-arrival ) = $/[ 0 ].Int, $/[ 1 ].Int;
+ $departure ~~ / (\d+) ':' (\d+) / ;
+ ( $!hour-departure, $!minute-departure ) = $/[ 0 ].Int, $/[ 1 ].Int;
+ }
+
+ method collide( Train $other-train ) {
+ my $this-arrival = $!hour-arrival * 60 + $!minute-arrival;
+ my $this-departure = $!hour-departure * 60 + $!minute-departure;
+ my $other-train-arrival = $other-train.hour-arrival * 60 + $other-train.minute-arrival;
+ my $other-train-departure = $other-train.hour-departure * 60 + $other-train.minute-departure;
+
+ $this-arrival <= $other-train-arrival && $other-train-departure <= $this-departure;
+ }
+}
+
+
+sub MAIN() {
+ my @arrivals = '10:20', '11:00', '11:10', '12:20', '16:20', '19:00';
+ my @departures = '10:30', '13:20', '12:40', '12:50', '20:20', '21:20';
+
+
+ my @trains.push: Train.new: arrival => @arrivals[ $_ ], departure => @departures[ $_ ] for 0 ..^ @arrivals.elems;
+
+ my $collisions = 0;
+ for 0 ..^ @trains.elems -> $current-train {
+ $collisions++ if @trains[ $current-train ].collide( @trains[ $_ ] ) for $current-train + 1 ..^ @trains.elems;
+ }
+
+ "Required platforms: { $collisions + 1 }".say;
+
+
+}