aboutsummaryrefslogtreecommitdiff
path: root/challenge-151/abigail/ruby/ch-2.rb
blob: ebdd805af58f441e3384000b264fa0af22dce259 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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