aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-02-14 03:52:14 +0000
committerGitHub <noreply@github.com>2022-02-14 03:52:14 +0000
commitc3e5809f848c7d77e0f3a2fe5dca93f85244558b (patch)
treed2824cc71a17e4b67085e12b49cb4e42b1215d4a
parent04948111062b5b3521db72a0da84bf21b4a91ea8 (diff)
parent36d3d5bb76298e94bdda0b4b1964a14a4c45212b (diff)
downloadperlweeklychallenge-club-c3e5809f848c7d77e0f3a2fe5dca93f85244558b.tar.gz
perlweeklychallenge-club-c3e5809f848c7d77e0f3a2fe5dca93f85244558b.tar.bz2
perlweeklychallenge-club-c3e5809f848c7d77e0f3a2fe5dca93f85244558b.zip
Merge pull request #5653 from andemark/branch-for-challenge-151
Challenge 151 Solutions (Raku)
-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;