aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-02-08 20:03:07 +0000
committerGitHub <noreply@github.com>2022-02-08 20:03:07 +0000
commit9e8211950a93c9370824c4cd25092d2c72cef692 (patch)
treeb02229e447f129e60744b12f9872796e22e41c40
parentbdaaa49f20ca56057a3a478a383f0af2253f6f6b (diff)
parenta09d0dd70c22dc386c4280cfae04158098dcc924 (diff)
downloadperlweeklychallenge-club-9e8211950a93c9370824c4cd25092d2c72cef692.tar.gz
perlweeklychallenge-club-9e8211950a93c9370824c4cd25092d2c72cef692.tar.bz2
perlweeklychallenge-club-9e8211950a93c9370824c4cd25092d2c72cef692.zip
Merge pull request #5629 from Abigail/abigail/week-151
Abigail/week 151
-rw-r--r--challenge-151/abigail/README.md26
-rw-r--r--challenge-151/abigail/awk/ch-1.awk42
-rw-r--r--challenge-151/abigail/awk/ch-2.awk21
-rw-r--r--challenge-151/abigail/bash/ch-1.sh41
-rw-r--r--challenge-151/abigail/bash/ch-2.sh23
-rw-r--r--challenge-151/abigail/c/ch-1.c96
-rw-r--r--challenge-151/abigail/c/ch-2.c52
-rw-r--r--challenge-151/abigail/go/ch-2.go48
-rw-r--r--challenge-151/abigail/lua/ch-1.lua45
-rw-r--r--challenge-151/abigail/lua/ch-2.lua25
-rw-r--r--challenge-151/abigail/node/ch-1.js33
-rw-r--r--challenge-151/abigail/node/ch-2.js21
-rw-r--r--challenge-151/abigail/pascal/ch-2.p41
-rw-r--r--challenge-151/abigail/perl/ch-1.pl39
-rw-r--r--challenge-151/abigail/perl/ch-2.pl43
-rw-r--r--challenge-151/abigail/python/ch-1.py32
-rw-r--r--challenge-151/abigail/python/ch-2.py19
-rw-r--r--challenge-151/abigail/r/ch-2.r22
-rw-r--r--challenge-151/abigail/ruby/ch-1.rb31
-rw-r--r--challenge-151/abigail/ruby/ch-2.rb17
-rw-r--r--challenge-151/abigail/t/ctest.ini9
-rw-r--r--challenge-151/abigail/t/input-1-12
-rw-r--r--challenge-151/abigail/t/input-2-12
-rw-r--r--challenge-151/abigail/t/output-1-1.exp2
-rw-r--r--challenge-151/abigail/t/output-2-1.exp2
25 files changed, 708 insertions, 26 deletions
diff --git a/challenge-151/abigail/README.md b/challenge-151/abigail/README.md
index 352bb54018..870c6804c1 100644
--- a/challenge-151/abigail/README.md
+++ b/challenge-151/abigail/README.md
@@ -4,50 +4,24 @@
* [AWK](awk/ch-1.awk)
* [Bash](bash/ch-1.sh)
-* [Bc](bc/ch-1.bc)
* [C](c/ch-1.c)
-* [Go](go/ch-1.go)
-* [Java](java/ch-1.java)
* [Lua](lua/ch-1.lua)
* [Node.js](node/ch-1.js)
-* [Pascal](pascal/ch-1.p)
* [Perl](perl/ch-1.pl)
* [Python](python/ch-1.py)
-* [R](r/ch-1.r)
* [Ruby](ruby/ch-1.rb)
-* [Scheme](scheme/ch-1.scm)
-* [Tcl](tcl/ch-1.tcl)
## Part 2
* [AWK](awk/ch-2.awk)
* [Bash](bash/ch-2.sh)
-* [Basic](basic/ch-2.bas)
-* [Bc](bc/ch-2.bc)
-* [Befunge-93](befunge-93/ch-2.bf93)
* [C](c/ch-2.c)
-* [Cobol](cobol/ch-2.cb)
-* [Csh](csh/ch-2.csh)
-* [Erlang](lua/ch-2.erl)
-* [Forth](lua/ch-2.fs)
-* [Fortran](fortran/ch-2.f90)
* [Go](go/ch-2.go)
-* [Java](java/ch-2.java)
* [Lua](lua/ch-2.lua)
-* [m4](m4/ch-2.m4)
-* [MMIX](mmix/ch-2.mms)
* [Node.js](node/ch-2.js)
-* [OCaml](ocaml/ch-2.ml)
* [Pascal](pascal/ch-2.p)
* [Perl](perl/ch-2.pl)
-* [PHP](php/ch-2.php)
-* [PostScript](postscript/ch-2.ps)
* [Python](python/ch-2.py)
* [R](r/ch-2.r)
-* [Rexx](rexx/ch-2.rexx)
* [Ruby](ruby/ch-2.rb)
-* [Scheme](scheme/ch-2.scm)
-* [Sed](sed/ch-2.sed)
-* [SQL](sql/ch-2.sql)
-* [Tcl](tcl/ch-2.tcl)
diff --git a/challenge-151/abigail/awk/ch-1.awk b/challenge-151/abigail/awk/ch-1.awk
new file mode 100644
index 0000000000..314efa9a0a
--- /dev/null
+++ b/challenge-151/abigail/awk/ch-1.awk
@@ -0,0 +1,42 @@
+#!/usr/bin/awk
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: awk -f ch-1.awk < input-file
+#
+
+{
+ #
+ # Read in tree
+ #
+ delete tree
+ D = 0
+ i = 0
+ for (k = 0; k < NF; k ++) {
+ if ($k == "|") {
+ D ++
+ i = 0
+ }
+ else {
+ tree [D, i ++] = $k == "*" ? 0 : 1
+ }
+ }
+
+ #
+ # Find first node without children
+ #
+ for (d = 0; d <= D; d ++) {
+ for (i = 0; i < 2 ^ d; i ++) {
+ if (tree [d, i] && !tree [d + 1, 2 * i] &&
+ !tree [d + 1, 2 * i + 1]) {
+ print d + 1
+ next
+ }
+ }
+ }
+}
+
+
diff --git a/challenge-151/abigail/awk/ch-2.awk b/challenge-151/abigail/awk/ch-2.awk
new file mode 100644
index 0000000000..732444708f
--- /dev/null
+++ b/challenge-151/abigail/awk/ch-2.awk
@@ -0,0 +1,21 @@
+#!/usr/bin/awk
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: awk -f ch-2.awk < input-file
+#
+
+function max (a, b) {
+ return a < b ? b : a
+}
+
+{
+ for (i = NF; i > 2; i --) {
+ $i = max($i + $(i + 2), $(i + 1))
+ }
+ print $1 + $3
+}
+
diff --git a/challenge-151/abigail/bash/ch-1.sh b/challenge-151/abigail/bash/ch-1.sh
new file mode 100644
index 0000000000..eff4fc05e6
--- /dev/null
+++ b/challenge-151/abigail/bash/ch-1.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: bash ch-1.sh < input-file
+#
+
+set -f
+
+declare -A tree
+
+while read -a tokens
+do tree=()
+ D=0
+ i=0
+ for token in ${tokens[@]}
+ do if [ $token == "|" ]
+ then D=$((D + 1))
+ i=0
+ else key=$D,$i
+ if [ $token != "*" ]
+ then tree[$key]=1
+ fi
+ i=$((i + 1))
+ fi
+ done
+
+ for ((d = 0; d <= D; d ++))
+ do for ((i = 0; i < 2 ** d; i ++))
+ do if [[ -v tree[$d,$i] ]] && \
+ [[ ! -v tree[$((d + 1)),$((2 * $i))] ]] && \
+ [[ ! -v tree[$((d + 1)),$((2 * $i + 1))] ]]
+ then echo $((d + 1))
+ break 2
+ fi
+ done
+ done
+done
diff --git a/challenge-151/abigail/bash/ch-2.sh b/challenge-151/abigail/bash/ch-2.sh
new file mode 100644
index 0000000000..cb009e0e16
--- /dev/null
+++ b/challenge-151/abigail/bash/ch-2.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: bash ch-2.sh < input-file
+#
+
+set -f
+
+while read -a h
+do h[${#h[@]}]=0
+ h[${#h[@]}]=0
+ for ((i = ${#h[@]} - 3; i >= 2; i --))
+ do ((val1 = ${h[$i]} + ${h[$((i + 2))]}))
+ ((val2 = ${h[$((i + 1))]}))
+ h[$i]=$((val1 < val2 ? val2 : val1))
+ done
+
+ echo $((${h[0]} + ${h[2]}))
+done
diff --git a/challenge-151/abigail/c/ch-1.c b/challenge-151/abigail/c/ch-1.c
new file mode 100644
index 0000000000..e4487ddaec
--- /dev/null
+++ b/challenge-151/abigail/c/ch-1.c
@@ -0,0 +1,96 @@
+# include <stdlib.h>
+# include <stdio.h>
+# include <string.h>
+# include <stdbool.h>
+# include <ctype.h>
+
+/*
+ * See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+ */
+
+/*
+ * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o < input-file
+ */
+
+int main (void) {
+ char * line = NULL;
+ size_t len = 0;
+ size_t str_len;
+
+ while ((str_len = getline (&line, &len, stdin)) != -1) {
+ char * line_ptr = line;
+ /*
+ * Count the number of '|' characters; this determines
+ * how many elements to allocate for our tree.
+ */
+ int size = 3;
+ while (* line_ptr) {
+ if (* line_ptr ++ == '|') {
+ size = 2 * size + 1;
+ }
+ }
+ bool * tree;
+ if ((tree = (bool *) malloc (size * sizeof (bool))) == NULL) {
+ perror ("Malloc tree failed");
+ exit (1);
+ }
+ for (size_t i = 0; i < size; i ++) {
+ tree [i] = false;
+ }
+
+ int D = 0;
+ int i = 0;
+ size_t offset = 0;
+ line_ptr = line;
+ /*
+ * Skip leading spaces
+ */
+ while (* line_ptr && isspace (* line_ptr)) {
+ line_ptr ++;
+ }
+ while (* line_ptr) {
+ if (* line_ptr == '|') {
+ D ++;
+ i = 0;
+ offset = 2 * offset + 1;
+ line_ptr ++;
+ continue;
+ }
+ if (* line_ptr == '*') {
+ i ++;
+ line_ptr ++;
+ continue;
+ }
+ if (isspace (* line_ptr)) {
+ while (* line_ptr && isspace (* line_ptr)) {
+ line_ptr ++;
+ }
+ continue;
+ }
+ tree [offset + i] = true;
+ i ++;
+ while (* line_ptr && !isspace (* line_ptr) && * line_ptr != '|') {
+ line_ptr ++;
+ }
+ }
+
+ int width = 1;
+ int k = 0;
+ bool done = false;
+ for (int d = 0; d <= D && !done; d ++) {
+ for (int i = 0; i < width && !done; i ++) {
+ if (tree [k] && !tree [2 * k + 1] && !tree [2 * k + 2]) {
+ printf ("%d\n", d + 1);
+ done = true;
+ }
+ k ++;
+ }
+ width *= 2;
+ }
+
+ free (tree);
+ }
+ free (line);
+
+ return (0);
+}
diff --git a/challenge-151/abigail/c/ch-2.c b/challenge-151/abigail/c/ch-2.c
new file mode 100644
index 0000000000..9c46968f80
--- /dev/null
+++ b/challenge-151/abigail/c/ch-2.c
@@ -0,0 +1,52 @@
+# include <stdlib.h>
+# include <stdio.h>
+# include <string.h>
+
+/*
+ * See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+ */
+
+/*
+ * Run as: cc -o ch-2.o ch-2.c; ./ch-2.o < input-file
+ */
+
+int max (int a, int b) {
+ return a < b ? b : a;
+}
+
+int main (void) {
+ char * line = NULL;
+ size_t len = 0;
+ size_t str_len;
+
+ while ((str_len = getline (&line, &len, stdin)) != -1) {
+ char * line_ptr = line;
+ int * h = NULL;
+ int val;
+ int offset;
+ int sz = 0;
+
+ while (sscanf (line_ptr, "%d%n", &val, &offset) == 1) {
+ if ((h = (int *) realloc (h, (2 + ++ sz) * sizeof (int))) == NULL) {
+ perror ("Recalloc failed");
+ exit (1);
+ }
+ h [sz - 1] = val;
+ line_ptr += offset;
+ }
+
+ h [sz + 0] = 0;
+ h [sz + 1] = 0;
+
+ for (int i = sz - 1; i >= 2; i --) {
+ h [i] = max (h [i] + h [i + 2], h [i + 1]);
+ }
+
+ printf ("%d\n", h [0] + h [2]);
+
+ free (h);
+ }
+ free (line);
+
+ return (0);
+}
diff --git a/challenge-151/abigail/go/ch-2.go b/challenge-151/abigail/go/ch-2.go
new file mode 100644
index 0000000000..a8b6725ffa
--- /dev/null
+++ b/challenge-151/abigail/go/ch-2.go
@@ -0,0 +1,48 @@
+package main
+
+//
+// See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+//
+
+//
+// Run as: go run ch-2.go < input-file
+//
+
+import (
+ "fmt"
+ "bufio"
+ "os"
+ "strconv"
+ "strings"
+)
+
+func max (a int, b int) int {
+ if a < b {
+ return b
+ }
+ return a
+}
+
+func main () {
+ var reader = bufio . NewReader (os. Stdin)
+ for {
+ var text, err = reader . ReadString ('\n')
+ if (err != nil) {
+ break
+ }
+
+ s := strings . Fields (strings . Trim (text, "\n"))
+ h := make ([] int, len (s))
+ for i, v := range s {
+ n, _ := strconv . Atoi (v)
+ h [i] = n
+ }
+ h = append (h, 0, 0)
+
+ for i := len (h) - 3; i >= 2; i -- {
+ h [i] = max (h [i] + h [i + 2], h [i + 1])
+ }
+
+ fmt . Println (h [0] + h [2])
+ }
+}
diff --git a/challenge-151/abigail/lua/ch-1.lua b/challenge-151/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..1d8664060f
--- /dev/null
+++ b/challenge-151/abigail/lua/ch-1.lua
@@ -0,0 +1,45 @@
+#!/opt/local/bin/lua
+
+--
+-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+for line in io . lines () do
+ local tree = {}
+ local d = 1
+ local i = 1
+ tree [d] = {}
+ for token in line : gmatch ("(%S+)") do
+ if token == "|" then
+ d = d + 1
+ i = 1
+ tree [d] = {}
+ goto end_loop
+ end
+ if token == "*" then
+ i = i + 1
+ goto end_loop
+ end
+
+ tree [d] [i] = 1
+ i = i + 1
+
+ ::end_loop::
+ end
+
+ for d, row in ipairs (tree) do
+ for i, _ in pairs (row) do
+ if not tree [d + 1] or
+ not tree [d + 1] [2 * i - 1] and not tree [d + 1] [2 * i] then
+ print (d)
+ goto end_main
+ end
+ end
+ end
+
+ ::end_main::
+end
diff --git a/challenge-151/abigail/lua/ch-2.lua b/challenge-151/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..d8ac15c101
--- /dev/null
+++ b/challenge-151/abigail/lua/ch-2.lua
@@ -0,0 +1,25 @@
+#!/opt/local/bin/lua
+
+--
+-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+--
+
+--
+-- Run as: lua ch-2.lua < input-file
+--
+
+for line in io . lines () do
+ local h = {}
+ for val in line : gmatch ("%d+") do
+ h [#h + 1] = val
+ end
+
+ h [#h + 1] = 0
+ h [#h + 1] = 0
+
+ for i = #h - 2, 3, -1 do
+ h [i] = math . max (h [i] + h [i + 2], h [i + 1])
+ end
+
+ print (h [1] + h [3])
+end
diff --git a/challenge-151/abigail/node/ch-1.js b/challenge-151/abigail/node/ch-1.js
new file mode 100644
index 0000000000..bf67eda21e
--- /dev/null
+++ b/challenge-151/abigail/node/ch-1.js
@@ -0,0 +1,33 @@
+#!/usr/local/bin/node
+
+//
+// See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+//
+
+//
+// Run as: node ch-1.js < input-file
+//
+
+ require ('readline')
+. createInterface ({input: process . stdin})
+. on ('line', line => {
+ let tree = line . split ("\|") . map (row => row . trim () . split (/ +/))
+
+ for (let d = 0; d < tree . length; d ++) {
+ if (d == tree . length - 1) {
+ return
+ }
+ let c_row = tree [d]
+ let n_row = tree [d + 1]
+ for (let i = 0; i < c_row . length; i ++) {
+ let ch1 = 2 * i
+ let ch2 = 2 * i + 1
+ if (c_row [i] != "*" &&
+ (ch1 >= n_row . length || n_row [ch1] == "*") &&
+ (ch2 >= n_row . length || n_row [ch2] == "*")) {
+ console . log (d + 1)
+ return;
+ }
+ }
+ }
+})
diff --git a/challenge-151/abigail/node/ch-2.js b/challenge-151/abigail/node/ch-2.js
new file mode 100644
index 0000000000..11a88c6bc7
--- /dev/null
+++ b/challenge-151/abigail/node/ch-2.js
@@ -0,0 +1,21 @@
+#!/usr/local/bin/node
+
+//
+// See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+//
+
+//
+// Run as: node ch-2.js < input-file
+//
+
+ require ('readline')
+. createInterface ({input: process . stdin})
+. on ('line', line => {
+ let h = line . trim () . split (/ +/) . map (n => +n)
+ h [h . length] = 0
+ h [h . length] = 0
+ for (let i = h . length - 3; i >= 2; i --) {
+ h [i] = Math . max (h [i] + h [i + 2], h [i + 1])
+ }
+ console . log (h [0] + h [2])
+})
diff --git a/challenge-151/abigail/pascal/ch-2.p b/challenge-151/abigail/pascal/ch-2.p
new file mode 100644
index 0000000000..18053673e2
--- /dev/null
+++ b/challenge-151/abigail/pascal/ch-2.p
@@ -0,0 +1,41 @@
+Program ch2;
+
+(* *)
+(* See https://theweeklychallenge.org/blog/perl-weekly-challenge-151 *)
+(* *)
+
+(* *)
+(* Run as: fpc -och-2.out ch-2.p; ./ch-2.out < input-file *)
+(* *)
+
+uses
+ math;
+
+var
+ h: array of integer;
+ i, sz: integer;
+
+begin
+ while not eof do begin
+ sz := 0;
+ setlength (h, sz);
+
+ while not eoln do begin
+ inc (sz);
+ setlength (h, sz);
+ read (h [sz - 1]);
+ end;
+
+ setlength (h, sz + 2);
+ h [sz + 0] := 0;
+ h [sz + 1] := 0;
+
+ for i := sz - 1 downto 2 do begin
+ h [i] := max (h [i] + h [i + 2], h [i + 1]);
+ end;
+
+ writeln (h [0] + h [2]);
+
+ readln;
+ end
+end.
diff --git a/challenge-151/abigail/perl/ch-1.pl b/challenge-151/abigail/perl/ch-1.pl
new file mode 100644
index 0000000000..73296d77c3
--- /dev/null
+++ b/challenge-151/abigail/perl/ch-1.pl
@@ -0,0 +1,39 @@
+#!/opt/perl/bin/perl
+
+use 5.032;
+
+use strict;
+use warnings;
+no warnings 'syntax';
+
+use experimental 'signatures';
+use experimental 'lexical_subs';
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: perl ch-1.pl < input-file
+#
+
+#
+# We'll store the tree in a triangular 2-d array, with
+# the children on node on position [$d, $k] on positions
+# [$d + 1, 2 * $k] and [$d + 1, 2 * $k + 1].
+#
+# Finding the first node without children is trivial.
+#
+TREE: while (<>) {
+ chomp;
+ my @tree = map {[map {$_ ne '*'} /\S+/g]} split /\|/;
+ foreach my $d (keys @tree) {
+ foreach my $i (keys @{$tree [$d]}) {
+ if ($tree [$d] [$i] && !$tree [$d + 1] [2 * $i]
+ && !$tree [$d + 1] [2 * $i + 1]) {
+ say $d + 1;
+ next TREE;
+ }
+ }
+ }
+}
diff --git a/challenge-151/abigail/perl/ch-2.pl b/challenge-151/abigail/perl/ch-2.pl
new file mode 100644
index 0000000000..df731f4cfe
--- /dev/null
+++ b/challenge-151/abigail/perl/ch-2.pl
@@ -0,0 +1,43 @@
+#!/opt/perl/bin/perl
+
+use 5.032;
+
+use strict;
+use warnings;
+no warnings 'syntax';
+
+use experimental 'signatures';
+use experimental 'lexical_subs';
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: perl ch-2.pl < input-file
+#
+
+use List::Util qw [max];
+
+#
+# We'll calculate the best way to rob the houses by working backwards.
+# For each house, there are two options: rob the house, or skip it.
+# The maximum value we get for robbing the house is the sum of
+# the value of the current house, plus the maximum we can get
+# if we started two houses down. The maximum value we can get by
+# not robbing this house is the best we can get by starting from
+# the next house. We'll add two empty houses to make everything work
+# out nicely.
+#
+# Note that we don't have to calculate the best option starting
+# from the second house, as we will always skip the second house.
+# And we must always pick the first house.
+#
+
+while (<>) {
+ my @h = (/[0-9]+/g, 0, 0);
+ $h [$_] = max $h [$_] + $h [$_ + 2], $h [$_ + 1] for reverse 2 .. $#h - 2;
+ say $h [0] + $h [2];
+}
+
+__END__
diff --git a/challenge-151/abigail/python/ch-1.py b/challenge-151/abigail/python/ch-1.py
new file mode 100644
index 0000000000..12dec88d86
--- /dev/null
+++ b/challenge-151/abigail/python/ch-1.py
@@ -0,0 +1,32 @@
+#!/usr/local/bin/python3
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+
+for line in fileinput . input ():
+ tree = list (map (lambda row: row . strip () . split (),
+ line . strip () . split ("|")))
+ for d in range (len (tree)):
+ if (d == len (tree) - 1):
+ print (d + 1)
+ break
+ done = False
+ for i in range (len (tree [d])):
+ if tree [d] [i] != "*":
+ ch1 = 2 * i
+ ch2 = 2 * i + 1
+ if ch1 >= len (tree [d + 1]) or (
+ (tree [d + 1] [ch1] == "*" and (
+ ch2 >= len (tree [d + 1]) or tree [d + 1] [ch2] == "*"))):
+ print (d + 1)
+ done = True
+ break
+ if done:
+ break
diff --git a/challenge-151/abigail/python/ch-2.py b/challenge-151/abigail/python/ch-2.py
new file mode 100644
index 0000000000..52522eff0b
--- /dev/null
+++ b/challenge-151/abigail/python/ch-2.py
@@ -0,0 +1,19 @@
+#!/usr/local/bin/python3
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: python ch-2.py < input-file
+#
+
+import fileinput
+
+for line in fileinput . input ():
+ h = list (map (lambda x: int (x), line . strip () . split ()))
+ h . append (0)
+ h . append (0)
+ for i in range (len (h) - 3, 1, -1):
+ h [i] = max (h [i] + h [i + 2], h [i + 1])
+ print (h [0] + h [2])
diff --git a/challenge-151/abigail/r/ch-2.r b/challenge-151/abigail/r/ch-2.r
new file mode 100644
index 0000000000..5d2e166d4a
--- /dev/null
+++ b/challenge-151/abigail/r/ch-2.r
@@ -0,0 +1,22 @@
+#!/usr/local/bin/Rscript
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: Rscript ch-2.r < input-file
+#
+
+stdin <- file ('stdin', 'r')
+repeat {
+ line <- readLines (stdin, n = 1)
+ if (length (line) == 0) {
+ break
+ }
+ h <- c (as.numeric (strsplit (line, " ") [[1]]), 0, 0)
+ for (i in seq (length (h) - 2, 3, -1)) {
+ h [[i]] <- max (c (h [[i]] + h [[i + 2]], h [[i + 1]]))
+ }
+ cat (h [[1]] + h [[3]], "\n")
+}
diff --git a/challenge-151/abigail/ruby/ch-1.rb b/challenge-151/abigail/ruby/ch-1.rb
new file mode 100644
index 0000000000..1164c5bdfc
--- /dev/null
+++ b/challenge-151/abigail/ruby/ch-1.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/ruby
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: ruby ch-1.rb < input-file
+#
+
+ARGF . each_line do |line|
+ tree = line . strip() . split(/\|/) . map do |row|
+ row . strip() . split(/ +/) . map do |x|
+ x == "*" ? false : true
+ end
+ end
+ done = false
+ for d in 0 .. tree . length() - 1 do
+ for i in 0 .. tree [d] . length() - 1 do
+ if tree [d] [i] && !tree [d + 1] [2 * i] &&
+ !tree [d + 1] [2 * i + 1] then
+ puts (d + 1)
+ done = true
+ break
+ end
+ end
+ if done then
+ break
+ end
+ end
+end
diff --git a/challenge-151/abigail/ruby/ch-2.rb b/challenge-151/abigail/ruby/ch-2.rb
new file mode 100644
index 0000000000..ebdd805af5
--- /dev/null
+++ b/challenge-151/abigail/ruby/ch-2.rb
@@ -0,0 +1,17 @@
+#!/usr/bin/ruby
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
+#
+
+#
+# Run as: ruby ch-2.rb < input-file
+#
+
+ARGF . each_line do |line|
+ (h = line . split . map do |n| n . to_i end) . push(0, 0)
+ (h . length - 3) . downto(2) do |i|
+ h[i] = [h[i] + h[i + 2], h[i + 1]] . max
+ end
+ puts (h[0] + h[2])
+end
diff --git a/challenge-151/abigail/t/ctest.ini b/challenge-151/abigail/t/ctest.ini
new file mode 100644
index 0000000000..0a8cb97d18
--- /dev/null
+++ b/challenge-151/abigail/t/ctest.ini
@@ -0,0 +1,9 @@
+#
+# Configuration file for running tests, using ctest.
+# See https://github.com/Abigail/Misc/blob/master/ctest
+#
+
+[names]
+1-1 = Given Examples
+2-1 = Given Examples
+
diff --git a/challenge-151/abigail/t/input-1-1 b/challenge-151/abigail/t/input-1-1
new file mode 100644
index 0000000000..61fb9ed0dc
--- /dev/null
+++ b/challenge-151/abigail/t/input-1-1
@@ -0,0 +1,2 @@
+1 | 2 3 | 4 5
+1 | 2 3 | 4 * * 5 | * 6
diff --git a/challenge-151/abigail/t/input-2-1 b/challenge-151/abigail/t/input-2-1
new file mode 100644
index 0000000000..14b0f0f2c6
--- /dev/null
+++ b/challenge-151/abigail/t/input-2-1
@@ -0,0 +1,2 @@
+2 4 5
+4 2 3 6 5 3
diff --git a/challenge-151/abigail/t/output-1-1.exp b/challenge-151/abigail/t/output-1-1.exp
new file mode 100644
index 0000000000..4792e70f33
--- /dev/null
+++ b/challenge-151/abigail/t/output-1-1.exp
@@ -0,0 +1,2 @@
+2
+3
diff --git a/challenge-151/abigail/t/output-2-1.exp b/challenge-151/abigail/t/output-2-1.exp
new file mode 100644
index 0000000000..dd80f6a91d
--- /dev/null
+++ b/challenge-151/abigail/t/output-2-1.exp
@@ -0,0 +1,2 @@
+7
+13