Skip to content

Commit

Permalink
Add 2024, day 6, first part
Browse files Browse the repository at this point in the history
  • Loading branch information
bewuethr committed Dec 6, 2024
1 parent ac56613 commit d560041
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 2024/day06/day06a
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env ruby

grid = File.readlines(ARGV[0]).map(&:chomp).map(&:chars)

y_range = (0...grid.length)
x_range = (0...grid.first.length)

y = grid.index { _1.include?("^") }
x = grid[y].index("^")

dy = -1
dx = 0

visited = Set.new

while y_range.cover?(y) && x_range.cover?(x)
visited.add([y, x])
dy, dx = dx, -dy if y_range.cover?(y + dy) && grid[y + dy][x + dx] == "#"
y += dy
x += dx
end

puts visited.size

0 comments on commit d560041

Please sign in to comment.