Solve 2025 day 1 and 2
This commit is contained in:
21
2025/d01.py
21
2025/d01.py
@@ -1,5 +1,22 @@
|
||||
from lib import get_data
|
||||
|
||||
data = get_data(__file__)
|
||||
print(data)
|
||||
NUM = 100
|
||||
|
||||
data = get_data(__file__)
|
||||
|
||||
pos = 50
|
||||
r1, r2 = 0, 0
|
||||
for line in data.splitlines():
|
||||
d = line[0]
|
||||
n = int(line[1:])
|
||||
dir = 1 if d == "R" else -1
|
||||
|
||||
for _ in range(n):
|
||||
pos = (pos + dir) % NUM
|
||||
if pos == 0:
|
||||
r2 += 1
|
||||
if pos == 0:
|
||||
r1 += 1
|
||||
|
||||
print(r1)
|
||||
print(r2)
|
||||
|
||||
34
2025/d02.py
Normal file
34
2025/d02.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from lib import get_data
|
||||
|
||||
|
||||
data = get_data(__file__)
|
||||
|
||||
def is_invalid(xs: str) -> bool:
|
||||
for seq_len in range(1, len(xs) // 2 + 1):
|
||||
if xs[:seq_len] == xs[seq_len:]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_invalid2(xs: str) -> bool:
|
||||
for seq_len in range(1, len(xs)):
|
||||
if len(xs) % seq_len != 0:
|
||||
continue
|
||||
for repeat in range(len(xs) // seq_len):
|
||||
i = seq_len * repeat
|
||||
if xs[:seq_len] != xs[i:i + seq_len]:
|
||||
break
|
||||
else:
|
||||
return True
|
||||
return False
|
||||
|
||||
r1, r2 = 0, 0
|
||||
for id_range in data.split(","):
|
||||
lo, up = list(map(int, id_range.split("-")))
|
||||
for id in range(lo, up + 1):
|
||||
if is_invalid(str(id)):
|
||||
r1 += id
|
||||
if is_invalid2(str(id)):
|
||||
r2 += id
|
||||
|
||||
print(r1)
|
||||
print(r2)
|
||||
@@ -7,7 +7,13 @@ Solutions and utility script for Advent of Code challenges in Python.
|
||||
Only twelve problems and no leaderboard this year. That means life will be less
|
||||
stressful and this will actually be more fun. Thank you Eric Wastl and let's go!
|
||||
|
||||
- Day 1:
|
||||
- Day 1: Maybe the hardest day 1 part 2 ever for me? I struggled to calculate
|
||||
the number of ticks on 0 directly and ended up just iterating over all the
|
||||
ticks naively. Maybe I should revisit this.
|
||||
- Day 2: The simple direct approach with iterating over all the IDs in the
|
||||
ranges just worked okay. Not pretty but acceptable.
|
||||
- Day 3:
|
||||
|
||||
|
||||
## AoC 2024
|
||||
|
||||
|
||||
Reference in New Issue
Block a user