Skip to content

Instantly share code, notes, and snippets.

@madebydna
Created August 18, 2010 21:17
Show Gist options
  • Save madebydna/536226 to your computer and use it in GitHub Desktop.
Save madebydna/536226 to your computer and use it in GitHub Desktop.
require 'json'
class Caterpillar
def pig_out(tree)
climb_tree(File.read(tree))
@tree_height = @tree.length - 1
@tree_height.downto(0) do |branch|
(0..(branch-1)).each do |twig|
@tree[branch - 1][twig] += [@tree[branch][twig], @tree[branch][twig+1]].max
end
end
@tree[0][0]
end
def climb_tree(tree)
@tree = JSON.parse(tree)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment