Created
December 5, 2017 19:27
-
-
Save nudded/b1413fce744d85ba4396cd4827faff0a to your computer and use it in GitHub Desktop.
day5.rb
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
input = File.readlines("inputs/day5.in") | |
stack = input.map &:to_i | |
def move(array, position) | |
offset = array[position] | |
if offset >=3 | |
array[position] -= 1 | |
else | |
array[position] += 1 | |
end | |
position + offset | |
end | |
position = 0 | |
length = stack.size | |
amount_of_steps = 0 | |
while position < length | |
position = move(stack, position) | |
amount_of_steps += 1 | |
end | |
puts amount_of_steps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment