This commit is contained in:
Tobias Radloff 2025-12-01 21:40:43 +01:00
commit 2c739b8f5f
No known key found for this signature in database
2 changed files with 4148 additions and 0 deletions

41
day01.py Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
f = open("day1input.txt", "r")
a = f.readlines()
b = list(map(str.strip, a))
c = list(map(lambda x: -int(x[1:]) if x[0] == "L" else int(x[1:]), b))
def part1(data: list[str], pos: int = 50, clicks: int = 100) -> int:
total = pos
zeroes = 0
for i in data:
total = (total + i) % clicks
if total == 0:
zeroes += 1
return zeroes
def part2(data: list[str], pos: int = 50, clicks: int = 100) -> int:
total = pos
zeroes = 0
for i in data:
if i >= 0:
m, total = divmod((total + i), clicks)
zeroes += m
else:
newtotal = (total + i) % clicks
if total == 0:
zeroes += -(i // clicks) - 1
elif -i > total:
zeroes += -((total + i) // clicks)
if newtotal == 0:
zeroes += 1
elif -i == total:
zeroes += 1
total = newtotal
return zeroes
print(f"Solution to part 1: {part1(c)}")
print(f"Solution to part 2: {part2(c)}")

4107
day01input.txt Normal file

File diff suppressed because it is too large Load Diff