This commit is contained in:
2025-12-02 19:45:45 +01:00
parent 774df0c7f0
commit 27942825a4

34
01/01-2.py Normal file
View File

@@ -0,0 +1,34 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#file = "./ex.txt"
file = "./input.txt"
def turn_lock(direction:str, steps:int, pos:int) -> list[int]:
zero_touch = 0
if direction == "R":
for _ in range(steps):
pos += 1
if pos == 100:
pos = 0
if pos == 0:
zero_touch += 1
else:
for _ in range(steps):
if pos == 0:
pos = 100
pos -= 1
if pos == 0:
zero_touch += 1
return [pos, zero_touch]
if __name__ == "__main__":
solution, position = 0, 50
input_file = open(file, "r")
for line in input_file:
line = line.strip()
if line == "":
continue
position, touched_zero = turn_lock(line[0], int(line[1:]), position)
solution += touched_zero
print(f"The Password is: {solution}")