Created
September 11, 2015 11:15
-
-
Save anonymous/e509aefb20ebb89fe9ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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