aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;