diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-09-07 10:18:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-07 10:18:21 +0100 |
| commit | 404d4e54bf6da59ce8a0ae57599c831d180b83f9 (patch) | |
| tree | 5309b810c2c9df0ac57d201ae1536ee0a2196428 | |
| parent | 94882719ec2d2ea35cfaf241de7d45b1b2ed1162 (diff) | |
| parent | fa2e939347ed4b34605aad080b0ffa517218162e (diff) | |
| download | perlweeklychallenge-club-404d4e54bf6da59ce8a0ae57599c831d180b83f9.tar.gz perlweeklychallenge-club-404d4e54bf6da59ce8a0ae57599c831d180b83f9.tar.bz2 perlweeklychallenge-club-404d4e54bf6da59ce8a0ae57599c831d180b83f9.zip | |
Merge pull request #2226 from Scimon/master
Challange one
| -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 $_ } ); +} |
