37 lines
730 B
Python
37 lines
730 B
Python
|
|
|
|
def dial(action, position):
|
|
if action[0] == "R":
|
|
position += action[1]
|
|
else:
|
|
position -= action[1]
|
|
|
|
position = position % 100
|
|
|
|
return position
|
|
|
|
def read_input(filename):
|
|
actions = []
|
|
for line in open(filename):
|
|
line = line.strip()
|
|
|
|
direction = line[:1]
|
|
steps = int(line[1:])
|
|
actions.append((direction,steps))
|
|
return actions
|
|
|
|
|
|
# filename = "day01/my_example_input"
|
|
# filename = "day01/example_input" # Output is 3
|
|
filename = "day01/input" # Output is 992
|
|
actions = read_input(filename)
|
|
|
|
position = 50
|
|
password = 0
|
|
for action in actions:
|
|
position = dial(action, position)
|
|
if position == 0:
|
|
password += 1
|
|
|
|
print(f"Password is {password}")
|