aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-087/feng-chang/raku/ch-1b.raku33
-rwxr-xr-xchallenge-087/feng-chang/raku/ch-2b.raku55
2 files changed, 88 insertions, 0 deletions
diff --git a/challenge-087/feng-chang/raku/ch-1b.raku b/challenge-087/feng-chang/raku/ch-1b.raku
new file mode 100755
index 0000000000..83629e7906
--- /dev/null
+++ b/challenge-087/feng-chang/raku/ch-1b.raku
@@ -0,0 +1,33 @@
+#!/bin/env raku
+
+=begin Challenge
+087, Task #1
+
+You are given an unsorted array of integers @N.
+Write a script to find the longest consecutive sequence. Print 0 if none sequence found.
+
+Example 1:
+ Input: @N = (100, 4, 50, 3, 2)
+ Output: (2, 3, 4)
+
+Example 2:
+ Input: @N = (20, 30, 10, 40, 50)
+ Output: 0
+
+Example 3:
+ Input: @N = (20, 19, 9, 11, 10)
+ Output: (9, 10, 11)
+
+=end Challenge
+
+sub MAIN(*@N) {
+ @N .= sort;
+ my \宽 = @N.elems - 1;
+
+ my @a = (0..宽-1 X 1..宽)
+ .grep({ $_[1] > $_[0] })
+ .grep({ $_[1] - $_[0] == @N[$_[1]] - @N[$_[0]] });
+ put do {
+ @a.elems > 0 ?? @a.max({ $_[1] - $_[0] }).map({ @N[$^a..$^b] }) !! 0;
+ }
+}
diff --git a/challenge-087/feng-chang/raku/ch-2b.raku b/challenge-087/feng-chang/raku/ch-2b.raku
new file mode 100755
index 0000000000..457119c152
--- /dev/null
+++ b/challenge-087/feng-chang/raku/ch-2b.raku
@@ -0,0 +1,55 @@
+#!/bin/env raku
+
+=begin Challenge
+
+You are given matrix m x n with 0 and 1.
+Write a script to find the largest rectangle containing only 1. Print 0 if none found.
+
+Example 1:
+Input:
+ [ 0 0 0 1 0 0 ]
+ [ 1 1 1 0 0 0 ]
+ [ 0 0 1 0 0 1 ]
+ [ 1 1 1 1 1 0 ]
+ [ 1 1 1 1 1 0 ]
+Output:
+ [ 1 1 1 1 1 ]
+ [ 1 1 1 1 1 ]
+
+Example 2:
+Input:
+ [ 1 0 1 0 1 0 ]
+ [ 0 1 0 1 0 1 ]
+ [ 1 0 1 0 1 0 ]
+ [ 0 1 0 1 0 1 ]
+Output: 0
+
+Example 3:
+Input:
+ [ 0 0 0 1 1 1 ]
+ [ 1 1 1 1 1 1 ]
+ [ 0 0 1 0 0 1 ]
+ [ 0 0 1 1 1 1 ]
+ [ 0 0 1 1 1 1 ]
+Output:
+ [ 1 1 1 1 ]
+ [ 1 1 1 1 ]
+
+=end Challenge
+
+my @N;
+for $*IN.lines -> $line {
+ @N.push($line.words».Int);
+}
+
+my \高 = @N.elems;
+my \宽 = @N[0].elems;
+
+my $a = ((0 ..^ 高-1 X 0 ..^ 宽-1) X (1 ..^ 高 X 1 ..^ 宽))
+ .grep({ $_[1;0] > $_[0;0] and $_[1;1] > $_[0;1] })
+ .grep({ @N[$_[0;0]..$_[1;0]; $_[0;1]..$_[1;1]].all == 1 })
+ .max({ ($_[1;0] - $_[0;0] + 1) * ($_[1;1] - $_[0;1] + 1) });
+
+if $a.elems > 1 {
+ put (1) xx ($a[1;1] - $a[0;1] + 1) for ^($a[1;0] - $a[0;0] + 1);
+}