day 1-2
This commit is contained in:
34
01/01-2.py
Normal file
34
01/01-2.py
Normal 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}")
|
||||
Reference in New Issue
Block a user