diff options
Diffstat (limited to 'challenge-077')
| -rw-r--r-- | challenge-077/simon-proctor/raku/ch-1.raku | 15 | ||||
| -rw-r--r-- | challenge-077/simon-proctor/raku/ch-2.raku | 30 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-077/simon-proctor/raku/ch-1.raku b/challenge-077/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..7d4d1fd09a --- /dev/null +++ b/challenge-077/simon-proctor/raku/ch-1.raku @@ -0,0 +1,15 @@ +#!/usr/bin/env raku + +use v6; + +#| Find the possible combinations of Fibonacci Numbers that add up to N +sub MAIN ( + UInt $N #= Target number +) { + my @combos = (1,1,*+*...^* > $N).unique.combinations.grep( -> @c { $N == [+] @c } ); + if @combos { + (($_.join( " + " ))~" = $N").say for @combos; + } else { + say 0; + } +} diff --git a/challenge-077/simon-proctor/raku/ch-2.raku b/challenge-077/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..60c94c7469 --- /dev/null +++ b/challenge-077/simon-proctor/raku/ch-2.raku @@ -0,0 +1,30 @@ +#!/usr/bin/env raku + +use v6; + +my %*SUB-MAIN-OPTS = :named-anywhere; + +#| Given a width and a list of O and X's +#| Makes a grid of the given width and counts the number of X's not touching any others +sub MAIN( + UInt $width, #= Width of the grid + :v(:$verbose) = False, #= Prints the Grid + *@cells where { "O"|"X" ~~ $_.all && $_.elems %% $width && $_.elems >= $width } +) { + my @grid = @cells.rotor($width); + @grid.map( *.join(" ")).join("\n").say if $verbose; + + my $count = 0; + for (0..^$width X, 0..^@grid.elems) -> @vec { + $count++ if @grid[@vec[1]][@vec[0]] ~~ "X" ~~ none(surrounding-cells( @vec, @grid )); + } + say $count; +} + +sub surrounds( @vec ) { + (-1..1 X, -1..1).grep( { ! ( $_[0] == $_[1] == 0 ) } ).map( { [ $_[0]+@vec[0], $_[1]+@vec[1] ] } ).grep( { $_[0]&$_[1] >= 0 } ); +} + +sub surrounding-cells( @vec, @grid ) { + surrounds(@vec).map( -> ($x,$y) { @grid[$y][$x] } ).grep( { defined $_ } ); +} |
