46 lines
810 B
Python
46 lines
810 B
Python
INPUT = "input.txt"
|
|
|
|
with open(INPUT, 'r') as file:
|
|
lines: list[str] = file.readlines()
|
|
|
|
place = 50
|
|
zeroes = 0
|
|
|
|
# returns new place
|
|
# dir, 0: L, 1: R
|
|
|
|
def move_dial(place: int, move: int, direction: int) -> int:
|
|
|
|
if direction == 0:
|
|
move *= -1
|
|
|
|
temp = place + move
|
|
|
|
if temp < 0:
|
|
place = 100 + (temp)
|
|
elif temp > 99:
|
|
place = abs(100 - temp)
|
|
else:
|
|
place = place + move
|
|
|
|
return place
|
|
|
|
for line in lines:
|
|
line: str = line.strip()
|
|
|
|
direction: int = 0 if line[0] == 'L' else 1
|
|
|
|
# We only actually care about the last two numbers
|
|
if len(line) > 3:
|
|
move = int(line[-2:])
|
|
else:
|
|
move = int(line[1:])
|
|
|
|
place = move_dial(place, move, direction)
|
|
|
|
if place == 0:
|
|
zeroes += 1
|
|
|
|
print(f'Dial Zero Count: {zeroes}')
|
|
|