aboutsummaryrefslogtreecommitdiff
path: root/challenge-151
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2022-02-14 03:33:37 +0000
committerMark <53903062+andemark@users.noreply.github.com>2022-02-14 03:33:37 +0000
commit36d3d5bb76298e94bdda0b4b1964a14a4c45212b (patch)
tree6e8415695a35e82d54207b74ef299211e1245a20 /challenge-151
parent512732b7f20ab5fc2f32dd307092bb82b58c97e1 (diff)
downloadperlweeklychallenge-club-36d3d5bb76298e94bdda0b4b1964a14a4c45212b.tar.gz
perlweeklychallenge-club-36d3d5bb76298e94bdda0b4b1964a14a4c45212b.tar.bz2
perlweeklychallenge-club-36d3d5bb76298e94bdda0b4b1964a14a4c45212b.zip
Challenge 151 Solutions (Raku)
Diffstat (limited to 'challenge-151')
-rw-r--r--challenge-151/mark-anderson/raku/ch-1.raku11
-rw-r--r--challenge-151/mark-anderson/raku/ch-2.raku4
2 files changed, 9 insertions, 6 deletions
diff --git a/challenge-151/mark-anderson/raku/ch-1.raku b/challenge-151/mark-anderson/raku/ch-1.raku
index 4797264da4..2e4c45274c 100644
--- a/challenge-151/mark-anderson/raku/ch-1.raku
+++ b/challenge-151/mark-anderson/raku/ch-1.raku
@@ -4,18 +4,17 @@ use Test;
is binary-tree-depth('1 | 2 3 | 4 5'), 2;
is binary-tree-depth('1 | 2 3 | 4 * * 5 | * 6'), 3;
-is binary-tree-depth('1 | 2 3 | 4 * * 5 | 6 * * 7 | 8 * * 9 | 10 *'), 5;
sub binary-tree-depth($str)
{
my $tree := $str.split(/\s\|\s/).map(*.split(/\s/));
- my $elems = 1;
- my $depth = 0;
+ my $nodes = 1;
+ my $depth;
- for $tree -> $nodes
+ for $tree -> $elems
{
- last unless $nodes.elems == $elems;
- $elems = ($elems - $nodes.comb('*')) * 2;
+ last unless $elems == $nodes;
+ $nodes = ($nodes - $elems.comb('*')) * 2;
$depth++;
}
diff --git a/challenge-151/mark-anderson/raku/ch-2.raku b/challenge-151/mark-anderson/raku/ch-2.raku
index b725a2b196..b086b7653a 100644
--- a/challenge-151/mark-anderson/raku/ch-2.raku
+++ b/challenge-151/mark-anderson/raku/ch-2.raku
@@ -2,6 +2,10 @@
# With help from https://www.geeksforgeeks.org/find-maximum-possible-stolen-value-houses/
+# I may have misunderstood the problem. At first I thought we have to rob the
+# first house but then I thought we just have to start at the first house and
+# consider robbing it. I went with my second instinct.
+
use Test;
is rob(2, 4, 5), 7;