Merge Bob's branch into benchmark branch
commit
992268ab47
|
|
@ -0,0 +1,3 @@
|
||||||
|
# AOC 2025
|
||||||
|
|
||||||
|
This folder hosts the code written by Bob
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
|
||||||
|
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}")
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
|
||||||
|
|
||||||
|
def dial(action, start_position):
|
||||||
|
if action[0] == "R":
|
||||||
|
position = start_position + action[1]
|
||||||
|
else:
|
||||||
|
position = start_position - action[1]
|
||||||
|
|
||||||
|
# Count rotations over "0" (multiples of 100)
|
||||||
|
zeros = int(abs(position) / 100)
|
||||||
|
|
||||||
|
# Negative position, or exactly "0", caused one extra "0" hit
|
||||||
|
# Except when starting at 0!
|
||||||
|
if position <= 0 and start_position != 0:
|
||||||
|
zeros += 1
|
||||||
|
|
||||||
|
position = position % 100
|
||||||
|
|
||||||
|
return position, zeros
|
||||||
|
|
||||||
|
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 6
|
||||||
|
filename = "day01/input" # Output is 6133
|
||||||
|
actions = read_input(filename)
|
||||||
|
|
||||||
|
position = 50
|
||||||
|
password = 0
|
||||||
|
|
||||||
|
for action in actions:
|
||||||
|
position, zeros = dial(action, position)
|
||||||
|
password += zeros
|
||||||
|
|
||||||
|
print(f"Password is {password}")
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,2 @@
|
||||||
|
L50
|
||||||
|
L5
|
||||||
Loading…
Reference in New Issue