From 36d3d5bb76298e94bdda0b4b1964a14a4c45212b Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 14 Feb 2022 03:33:37 +0000 Subject: Challenge 151 Solutions (Raku) --- challenge-151/mark-anderson/raku/ch-1.raku | 11 +++++------ challenge-151/mark-anderson/raku/ch-2.raku | 4 ++++ 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; -- cgit