advent-of-code/2015/day-03/common.rb
Patrick Auernig 3c57921438 Refactor 2015 days 01 to 10
Split parts into separate files and remove some unused files
2021-12-08 01:05:17 +01:00

19 lines
380 B
Ruby

INPUT = File
.readlines(ARGV.first, chomp: true)
.lazy.map do |line|
line.each_char.map { |d| position_modifier(d) }
end
def position_modifier(direction)
case direction
when ">" then [1, 0]
when "<" then [-1, 0]
when "^" then [0, 1]
when "v" then [0, -1]
end
end
def apply_direction(position, change)
position.map.with_index { |v, i| v + change[i] }
end