3 $triangle = File
.readlines('euler67-triangle.txt').map
{|line
| line
.chomp
.split
.map
{|s
| s
.to_i
}}
5 def find_best(triangle
)
6 log
= Logger
.new(STDERR)
7 log
.level
= Logger
::WARN
10 triangle
.each
do |line
|
11 log
.info
{"Checking line #{line}"}
13 line
.each_index
do |i
|
14 this_line_totals
<< [i
== 0 ? 0 : last_line_totals
[i-1
] + line
[i
],
15 i
== last_line_totals
.length
? 0 : last_line_totals
[i
] + line
[i
]].max
17 log
.info
{"Best totals for line #{line} are #{this_line_totals}"}
18 last_line_totals
= this_line_totals
25 puts find_best
$triangle