Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2015 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6dafbf7e8332742f7d46 to your computer and use it in GitHub Desktop.
Save anonymous/6dafbf7e8332742f7d46 to your computer and use it in GitHub Desktop.
class Rabbit
@@result = 1
def read
File.open("./input", "r") do |file|
file.each_line do |line|
trace(line.chomp, 2)
end
end
end
private
def trace(stairs, jump)
max_jump = []
stairs = stairs.to_i
while stairs >= jump do
stairs -= jump
max_jump << jump
end
max_jump << 1 if stairs == 1
options(max_jump)
puts @@result
end
def options(max_jump)
max_jump.each_with_index do |jump, index|
if jump == 2
max_jump[index] = 1
max_jump.insert(index + 1, jump - 1)
@@result += 1
options(max_jump)
end
end
end
end
check = Rabbit.new
check.read
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment