Skip to content

Commit

Permalink
feat(2024): day 14
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleSmoke committed Dec 14, 2024
1 parent 2b52b8a commit fa29b16
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 2024/day_14/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
import re

input_file = "input"

width, height = 101 if input_file == "input" else 11, 103 if input_file == "input" else 7
data = [tuple(map(int, re.findall(r"-?\d+", line))) for line in open(input_file).readlines()]


def solve(robots, steps):
top_left, top_right, bottom_left, bottom_right = 0, 0, 0, 0
for x, y, dx, dy in robots:
x = (x + dx * steps) % width
y = (y + dy * steps) % height

top_left += x > width // 2 and y < height // 2
top_right += x < width // 2 and y < height // 2
bottom_left += x > width // 2 and y > height // 2
bottom_right += x < width // 2 and y > height // 2

return top_left * top_right * bottom_left * bottom_right


print(solve(data.copy(), 100))
print(min(range(10000), key=lambda x: solve(data.copy(), x)))

0 comments on commit fa29b16

Please sign in to comment.