2025(01): do part 2

Marit had to help me :D.
This commit is contained in:
2025-12-01 22:08:58 +01:00
parent c99029a6de
commit b39d54cd5b
3 changed files with 4422 additions and 2 deletions

4392
2025/01/inputmarit Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,3 @@
# TODO: Get the inout.
with open("input", "r") as fp:
moves = fp.readlines()

30
2025/01/part2.py Normal file
View File

@ -0,0 +1,30 @@
infile="input"
with open(infile, "r") as fp:
moves = fp.readlines()
counter = 50
code = 0
for idx, move in enumerate(moves):
direction, number = move[0], int(move[1:])
assert direction in ['L', 'R'], f"Direction should be left (L) or right (R), not '{direction}'"
assert number > 0, f"Number should be positive, not '{number}'"
# Do counterthings
prev_counter = counter
sgn = 1 if direction == "R" else -1
counter += sgn*number
# Going left is weird
if direction == 'L':
if prev_counter != 0 and counter % 100 == 0:
code += 1
if prev_counter == 0 and counter % 100 != 0:
code -= 1
# If we cross zero, let's store that.
code += abs(counter // 100)
counter %= 100
print("The actual password is:", code)