source/euler18.rb
# NOTE: As there are only 16384 routes, it is possible to solve this problem by 
# trying every route. However, Problem 67, is the same challenge with a 
# triangle containing one-hundred rows; it cannot be solved by brute force, and 
# requires a clever method! ;o)
As there are only 16384 routes, it is possible to solve this problem by
trying every route. However, Problem 67, is the same challenge with a
triangle containing one-hundred rows; it cannot be solved by brute force, and
requires a clever method. ;o)
As there are only 16384 routes it is possible to solve this problem by trying every route . However Problem 67 is the same challenge with a triangle containing one - hundred rows ; it cannot be solved by brute force and requires a clever method . ; o )
def largest_sum(triangle)
  top_heavy = triangle.reverse
  top_heavy.each_with_index do |line, y|
    next if y == triangle.length
    x = 0
    line.each_cons(2) do |first, second|
      top_heavy[y + 1][x] += [first, second].max
      x += 1
    end
  end
  top_heavy.last.last
end
def largest_sum ( triangle ) top_heavy = triangle . reverse top_heavy . each_with_index do | line , y | next if y == triangle . length x = 0 line . each_cons ( 2 ) do | first , second | top_heavy [ y + 1 ] [ x ] += [ first , second ] . max x += 1 end end top_heavy . last . last end
NOTE: As there are only 16384 routes, it is possible to solve this problem by
trying every route.
NOTE : As there are only 16384 routes it is possible to solve this problem by trying every route .
triangle