Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2015 11:15
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/e509aefb20ebb89fe9ab to your computer and use it in GitHub Desktop.
Save anonymous/e509aefb20ebb89fe9ab to your computer and use it in GitHub Desktop.
class Rabbit
@result = 0
def read
File.open("./input", "r") do |file|
file.each_line do |line|
args = line.split
jump = args[0].to_i
stairs = args[1].to_i
trace(jump, stairs)
end
end
end
private
def trace(jump, stairs, position = 0)
for i in 1..jump do
if position + i < stairs
puts "before increment #{position}"
position += i
puts "after increment #{position}"
trace(jump, stairs, position)
elsif position + jump == stairs
puts "stairs end!"
@result += 1
puts "result #{@result}"
end
end
end
def show(res)
puts "SUM #{res}"
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