From 63afef8b9bfa507fca0fb5a9610a19043ffa14b9 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 7 Sep 2020 09:35:24 +0100 Subject: Challange one --- challenge-077/simon-proctor/raku/ch-1.raku | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 challenge-077/simon-proctor/raku/ch-1.raku (limited to 'challenge-077') 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; + } +} -- cgit From fa2e939347ed4b34605aad080b0ffa517218162e Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 7 Sep 2020 10:00:40 +0100 Subject: O and X's --- challenge-077/simon-proctor/raku/ch-2.raku | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 challenge-077/simon-proctor/raku/ch-2.raku (limited to 'challenge-077') 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 $_ } ); +} -- cgit