Solved 2025 Day 1 Parts 1 & 2
This commit is contained in:
1 parent
4f07ea9f81
commit
1a711cd261
23 files changed
+9528
No files matched your search
@@ -0,0 +1,45 @@
|
||||
INPUT = "input.txt"
|
||||
|
||||
with open(INPUT, 'r') as file:
|
||||
lines: list[str] = file.readlines()
|
||||
|
||||
place = 50
|
||||
zeroes = 0
|
||||
|
||||
# returns new place
|
||||
# dir, 0: L, 1: R
|
||||
|
||||
def move_dial(place: int, move: int, direction: int) -> int:
|
||||
|
||||
if direction == 0:
|
||||
move *= -1
|
||||
|
||||
temp = place + move
|
||||
|
||||
if temp < 0:
|
||||
place = 100 + (temp)
|
||||
elif temp > 99:
|
||||
place = abs(100 - temp)
|
||||
else:
|
||||
place = place + move
|
||||
|
||||
return place
|
||||
|
||||
for line in lines:
|
||||
line: str = line.strip()
|
||||
|
||||
direction: int = 0 if line[0] == 'L' else 1
|
||||
|
||||
# We only actually care about the last two numbers
|
||||
if len(line) > 3:
|
||||
move = int(line[-2:])
|
||||
else:
|
||||
move = int(line[1:])
|
||||
|
||||
place = move_dial(place, move, direction)
|
||||
|
||||
if place == 0:
|
||||
zeroes += 1
|
||||
|
||||
print(f'Dial Zero Count: {zeroes}')
|
||||
|
||||
Reference in new issue
Block a user