2025(01): do part 2
Marit had to help me :D.
This commit is contained in:
4392
2025/01/inputmarit
Normal file
4392
2025/01/inputmarit
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,3 @@
|
|||||||
# TODO: Get the inout.
|
|
||||||
|
|
||||||
with open("input", "r") as fp:
|
with open("input", "r") as fp:
|
||||||
moves = fp.readlines()
|
moves = fp.readlines()
|
||||||
|
|
||||||
|
|||||||
30
2025/01/part2.py
Normal file
30
2025/01/part2.py
Normal 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)
|
||||||
Reference in New Issue
Block a user