aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-11 10:07:57 +0100
committerGitHub <noreply@github.com>2020-09-11 10:07:57 +0100
commit374ef3f6e71af27e849f41512f14a21e7b160995 (patch)
tree93b30d49d14e219a47ed402e7c6535aff7300444
parentdb120e5c02201f9c275f86f5fe7530ab4e255a3e (diff)
parente8407a68d545555f2499578e29389c1c3abbfaf2 (diff)
downloadperlweeklychallenge-club-374ef3f6e71af27e849f41512f14a21e7b160995.tar.gz
perlweeklychallenge-club-374ef3f6e71af27e849f41512f14a21e7b160995.tar.bz2
perlweeklychallenge-club-374ef3f6e71af27e849f41512f14a21e7b160995.zip
Merge pull request #2250 from p6steve/new-branch
new submission for challenge 77
-rw-r--r--challenge-077/p6steve/README1
-rwxr-xr-xchallenge-077/p6steve/raku/ch-1.raku8
-rwxr-xr-xchallenge-077/p6steve/raku/ch-2.raku48
3 files changed, 57 insertions, 0 deletions
diff --git a/challenge-077/p6steve/README b/challenge-077/p6steve/README
new file mode 100644
index 0000000000..9c75a3a5c5
--- /dev/null
+++ b/challenge-077/p6steve/README
@@ -0,0 +1 @@
+Solution by p6steve
diff --git a/challenge-077/p6steve/raku/ch-1.raku b/challenge-077/p6steve/raku/ch-1.raku
new file mode 100755
index 0000000000..d555c30470
--- /dev/null
+++ b/challenge-077/p6steve/raku/ch-1.raku
@@ -0,0 +1,8 @@
+sub MAIN(UInt $N is required) {
+ my @answers =
+ (1, 1, * + * ...^ *>= $N)[1..*] #Fibonacci numbers >= $N (slice off duplicated 1)
+ .combinations #... all possible combinations
+ .grep({.sum == $N}); #... which add to $N
+
+ say +@answers ?? @answers.join("\n") !! 0;
+}
diff --git a/challenge-077/p6steve/raku/ch-2.raku b/challenge-077/p6steve/raku/ch-2.raku
new file mode 100755
index 0000000000..c98f790934
--- /dev/null
+++ b/challenge-077/p6steve/raku/ch-2.raku
@@ -0,0 +1,48 @@
+my \X = 'X';
+my \O = 'O';
+
+my @window = [
+ [ O, O, O ],
+ [ O, X, O ],
+ [ O, O, O ],
+];
+
+my @matrix1 = [
+ [ O, O, X ],
+ [ X, O, O ],
+ [ X, O, O ],
+];
+
+my @matrix2 = [
+ [ O, O, X, O ],
+ [ X, O, O, O ],
+ [ X, O, O, X ],
+ [ O, X, O, O ],
+];
+
+sub x-walk( @x ) {
+ my $count = 0;
+ loop (my $m=0; $m < @x[*]; $m++) { #matrix cols
+ loop (my $n=0; $n < @x; $n++) { #... and rows
+ next unless @x[$m;$n] eq X;
+ my @w = @window;
+ my $x-hits = 0;
+ loop (my $i=0; $i <= 2; $i++) { #window cols
+ my $m-win = $m-1 + $i;
+ next unless 0 <= $m-win < @x[*];
+ loop (my $j=0; $j <= 2; $j++) { #... and rows
+ my $n-win = $n-1 + $j;
+ next unless 0 <= $n-win < @x;
+ @w[$i;$j] = @x[$m-win;$n-win];
+ $x-hits++ if @w[$i;$j] eq X;
+ }
+ }
+ $count++ unless $x-hits > 1;
+ }
+ }
+ return $count;
+}
+
+say x-walk( @matrix1 );
+say x-walk( @matrix2 );
+