diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-09-14 02:56:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-14 02:56:21 +0100 |
| commit | d86fd40dcad747cb198fbef75b0177caca098586 (patch) | |
| tree | f8e6a4661fe7b66c1312cac08525e174aad76074 | |
| parent | 7925e18dcdc1b0f5c6ec31ea743aad85d46b326c (diff) | |
| parent | d0dff42c33aa3fe309b3fc41253e4a72558917d5 (diff) | |
| download | perlweeklychallenge-club-d86fd40dcad747cb198fbef75b0177caca098586.tar.gz perlweeklychallenge-club-d86fd40dcad747cb198fbef75b0177caca098586.tar.bz2 perlweeklychallenge-club-d86fd40dcad747cb198fbef75b0177caca098586.zip | |
Merge pull request #2276 from therealjcm/branch-for-challenge-077
Challenge answers for week #77 in Raku
| -rw-r--r-- | challenge-077/jason-messer/raku/ch-1.p6 | 13 | ||||
| -rw-r--r-- | challenge-077/jason-messer/raku/ch-2.p6 | 30 |
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); |
