aboutsummaryrefslogtreecommitdiff
path: root/challenge-126
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-08-16 18:18:41 -0400
committerchirvasitua <stuart-little@users.noreply.github.com>2021-08-16 18:18:41 -0400
commitb0e8d4df73402d7db49599085b1fec8203893c4b (patch)
tree4dd0b91e4bb626ce558d9b9da9905e5ec0437b41 /challenge-126
parent5acfb9f5cd9b2f59e09c3dd69e3e2b9d2806cca6 (diff)
downloadperlweeklychallenge-club-b0e8d4df73402d7db49599085b1fec8203893c4b.tar.gz
perlweeklychallenge-club-b0e8d4df73402d7db49599085b1fec8203893c4b.tar.bz2
perlweeklychallenge-club-b0e8d4df73402d7db49599085b1fec8203893c4b.zip
1st commit on 126_raku
Diffstat (limited to 'challenge-126')
-rwxr-xr-xchallenge-126/stuart-little/raku/ch-1.raku12
-rwxr-xr-xchallenge-126/stuart-little/raku/ch-2.raku21
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-126/stuart-little/raku/ch-1.raku b/challenge-126/stuart-little/raku/ch-1.raku
new file mode 100755
index 0000000000..b219539164
--- /dev/null
+++ b/challenge-126/stuart-little/raku/ch-1.raku
@@ -0,0 +1,12 @@
+#!/usr/bin/env raku
+use v6;
+
+# run <script> <number>
+
+sub no1($nr) {
+ $nr.chars==0 && return 0;
+ ($nr.substr(0,1) eq '1') && return 9**($nr.chars-1);
+ return ($nr.substr(0,1).Int-1) * 9**($nr.chars-1) + no1($nr.substr(1));
+}
+
+say((@*ARGS[0] !~~ m/1/) ?? (no1(@*ARGS[0])) !! (no1(@*ARGS[0])-1))
diff --git a/challenge-126/stuart-little/raku/ch-2.raku b/challenge-126/stuart-little/raku/ch-2.raku
new file mode 100755
index 0000000000..0acd479e12
--- /dev/null
+++ b/challenge-126/stuart-little/raku/ch-2.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+use v6;
+
+# run <script>
+
+sub nbrs(@mat, $i, $j) {
+ return ((-1..1) X (-1..1)).map({ [$i+$_.[0], $j+$_.[1]] }).grep({ 0 <= $_.[0] < @mat.elems && 0 <= $_.[1] < @mat[0].elems && ($_.[0] != $i || $_.[1] != $j) }).Array
+}
+my @in = $=finish.lines.map({ $_.split(/\s+/).Array });
+
+for ((0..^@in.elems) X (0..^@in[0].elems)) -> ($i, $j) {
+ print( ((@in[$i][$j] eq 'x') ?? (@in[$i][$j]) !! (nbrs(@in,$i,$j).grep({ @in[$_[0]][$_[1]] eq 'x' }).elems)) ~ " " );
+ ($j == @in[0].elems-1) && print("\n");
+}
+
+=finish
+x * * * x * x x x x
+* * * * * * * * * x
+* * * * x * x * x *
+* * * x x * * * * *
+x * * * x * * * * x