aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-077/jason-messer/raku/ch-1.p613
-rw-r--r--challenge-077/jason-messer/raku/ch-2.p630
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-077/jason-messer/raku/ch-1.p6 b/challenge-077/jason-messer/raku/ch-1.p6
new file mode 100644
index 0000000000..822606694f
--- /dev/null
+++ b/challenge-077/jason-messer/raku/ch-1.p6
@@ -0,0 +1,13 @@
+#! /usr/bin/env rakudo
+
+# slight cheat in fib sequence to naturally exclude 0 and repeated 1
+sub fibs-sum( Int $n where * > 0) {
+ my $a := { 1, 2, * + * ... * + * > $n };
+ gather for $a($n).combinations.grep( { .sum == $n }) -> $solution {
+ take "{$solution.join: ' + '} = $n";
+ }
+}
+
+.say for fibs-sum(6);
+.say for fibs-sum(9);
+#.say for fibs-sum(100);
diff --git a/challenge-077/jason-messer/raku/ch-2.p6 b/challenge-077/jason-messer/raku/ch-2.p6
new file mode 100644
index 0000000000..8fa65625cc
--- /dev/null
+++ b/challenge-077/jason-messer/raku/ch-2.p6
@@ -0,0 +1,30 @@
+use v6.d;
+
+my @matrix1 = qw/O O X/,
+ qw/X O O/,
+ qw/X O O/;
+
+my @matrix2 = qw/O O X O/,
+ qw/X O O O/,
+ qw/X O O X/,
+ qw/O X O O/;
+
+sub find-no-neighbors(@a) {
+ my @coords = gather for ^@a.elems -> $x {
+ for ^@a[$x].elems -> $y {
+ next unless @a[$x][$y] eq 'X';
+ # all offsets, excluding 0,0
+ for ( ((0,1,-1) X (0,1,-1))[1..*] ) {
+ state $neighbors = False;
+ next unless 0 <= $x + .first < @a.elems;
+ next unless 0 <= $y + .tail < @a[$x].elems;
+ $neighbors = True if @a[$x + .first][$y + .tail] eq 'X';
+ LAST { take $x => $y if !$neighbors }
+ }
+ }
+ }
+ return @coords.elems;
+}
+
+say find-no-neighbors(@matrix1);
+say find-no-neighbors(@matrix2);