-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
67 lines (47 loc) · 1.56 KB
/
solution.py
File metadata and controls
67 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Advent of Code 2025 - Day 1
"""
def part1(input_data, current_location):
"""Solve part 1 of the puzzle."""
passing_zero_times = 0
for instruction in input_data:
direction = instruction[0]
steps = int(instruction[1:])
if direction == "R":
current_location = current_location + steps
else:
current_location = current_location - steps
current_location = current_location % 100
if current_location == 0:
passing_zero_times += 1
return passing_zero_times
def part2(input_data, current_location):
"""Solve part 2 of the puzzle."""
passing_zero_times = 0
for instruction in input_data:
direction = instruction[0]
steps = int(instruction[1:])
if direction == "R":
k0 = (100 - current_location) % 100
end_location = (current_location + steps) % 100
else:
k0 = current_location % 100
end_location = (current_location - steps) % 100
if k0 == 0:
k0 = 100
if steps >= k0:
passing_zero_times += 1 + (steps - k0) // 100
current_location = end_location
return passing_zero_times
def main():
# Read input
with open("day01/input.txt", "r") as f:
input_data = f.read().strip().split("\n")
initial_location = 50
# Solve
result1 = part1(input_data, initial_location)
result2 = part2(input_data, initial_location)
print(f"Part 1: {result1}")
print(f"Part 2: {result2}")
if __name__ == "__main__":
main()