aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScimon <simon.proctor@gmail.com>2021-08-17 14:33:57 +0100
committerScimon <simon.proctor@gmail.com>2021-08-17 14:33:57 +0100
commit3a2671eae0c18f0289911c652d159b78591e5e33 (patch)
tree537d5f2b2e78073e407a43d43cdc06095dc134b8
parentc7b3b6dc639b05fec2c84f6959bd69928f9fa909 (diff)
downloadperlweeklychallenge-club-3a2671eae0c18f0289911c652d159b78591e5e33.tar.gz
perlweeklychallenge-club-3a2671eae0c18f0289911c652d159b78591e5e33.tar.bz2
perlweeklychallenge-club-3a2671eae0c18f0289911c652d159b78591e5e33.zip
Now with random maps
-rw-r--r--challenge-126/simon-proctor/raku/ch-2.raku12
1 files changed, 12 insertions, 0 deletions
diff --git a/challenge-126/simon-proctor/raku/ch-2.raku b/challenge-126/simon-proctor/raku/ch-2.raku
index 025f530b0d..55130be0f9 100644
--- a/challenge-126/simon-proctor/raku/ch-2.raku
+++ b/challenge-126/simon-proctor/raku/ch-2.raku
@@ -35,6 +35,18 @@ multi sub MAIN("example") {
find-numbers( $example ).say;
}
+subset PInt of Int where * > 0;
+subset Density of Int where 1 <= * <= 50;
+
+#| Given a width, height and mine density (1-50%) makes a map then prints the numbers
+multi sub MAIN( PInt $width, PInt $height, Density $density ) {
+ my @opts = ( |("x" xx $density), |("*" xx (100-$density)) );
+ my $grid = (^$height).map( { @opts.roll($width).join( " " ) } ).join("\n");
+ $grid.say;
+ ("-" xx $width).join("-").say;
+ find-numbers( $grid ).say;
+}
+
sub parse-mines( Str $input ) {
return $input.lines.map( { $_.comb(/\S/).Array } ).Array;
}