2025 - Day 1 part 2

This commit is contained in:
kleph 2025-12-02 01:58:39 +01:00
parent 35378c059b
commit e1fa29815d

33
2025/1/1_2.py Normal file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env python
# 2025 - Advent Of Code 1 - part 2
# file = 'input_example.txt'
file = 'input.txt'
dial = 50
count = 0
with open(file, encoding="utf-8") as f:
for line in f.readlines():
direction = line[0]
distance = int(line[1:])
if direction == 'L':
if dial == 0:
was_zero = 0
else:
was_zero = 1
dial -= distance
if dial <= 0:
count += abs(int(dial / 100)) + was_zero
print(f'Left {distance=} {dial=} {count=}')
elif direction == 'R':
dial += distance
if dial > 99:
count += int(dial / 100)
print(f'Right {distance=} {dial=} {count=}')
dial = dial % 100
# print(f'{dial=}')
print(count)