Skip to content

Instantly share code, notes, and snippets.

@nudded
Created December 5, 2017 19:27
Show Gist options
  • Save nudded/b1413fce744d85ba4396cd4827faff0a to your computer and use it in GitHub Desktop.
Save nudded/b1413fce744d85ba4396cd4827faff0a to your computer and use it in GitHub Desktop.
day5.rb
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