Created
September 11, 2015 12:34
-
-
Save anonymous/7cb47d7eccda988ec7c3 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
5 |
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 = 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