47 lines
933 B
Python
47 lines
933 B
Python
INPUT = "input.txt"
|
|
|
|
with open(INPUT, 'r') as file:
|
|
lines: list[str] = file.readlines()
|
|
|
|
place = 50
|
|
zeroes = 0
|
|
|
|
# returns (new place, zeroes)
|
|
# dir, 0: L, 1: R
|
|
def move_dial(place: int, move: int, direction: int) -> tuple[int, int]:
|
|
|
|
if direction == 0:
|
|
move *= -1
|
|
|
|
temp = place + move
|
|
|
|
if temp < 0:
|
|
if place == 0:
|
|
return (100 + (temp), 0)
|
|
return (100 + (temp), 1)
|
|
elif temp > 99:
|
|
return (abs(100 - temp), 1)
|
|
elif temp == 0:
|
|
return (temp, 1)
|
|
else:
|
|
return (temp, 0)
|
|
|
|
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:])
|
|
zeroes += int(line[1])
|
|
else:
|
|
move = int(line[1:])
|
|
|
|
place, z = move_dial(place, move, direction)
|
|
|
|
zeroes += z
|
|
|
|
print(f'Dial Zero Count: {zeroes}')
|
|
|