diff options
| -rw-r--r-- | challenge-151/abigail/ruby/ch-1.rb | 31 | ||||
| -rw-r--r-- | challenge-151/abigail/ruby/ch-2.rb | 17 |
2 files changed, 48 insertions, 0 deletions
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 |
