mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2025-12-09 20:24:57 +00:00
aoc 2025 1+2
This commit is contained in:
13
2025/01/Findings.md
Normal file
13
2025/01/Findings.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Day 01
|
||||
|
||||
> First of all, what a joy not having 24 days, and no leaderboard. I actually really enjoy it and get more out of it. Turn off LLM, and just have fun 🤩
|
||||
|
||||
## Part 1
|
||||
|
||||
That was quite straight forward, nothing notable here. But it has been a while since I last used mod.
|
||||
|
||||
## Part 2
|
||||
|
||||
This was fun. So i wanted to (of course) not brute force it. Solution: first: calculate how many "empty" rounds the instruction had. e.g. `L106` would become simply `L6`) and simply increase by one. Now counting if we crossed `0` was interesting. I calculated the _distance to zero_ by checking how far the zero was, depending on the direction. And then simply seeing if the distance to travel was equally greater than the distance to zero.
|
||||
|
||||
The gotcha which took me a few minutes, was that I was adding a zero to much, if I was starting at `0`. But the test data caught that as well!
|
||||
49
2025/01/main.py
Normal file
49
2025/01/main.py
Normal file
@@ -0,0 +1,49 @@
|
||||
def calc_1(lines):
|
||||
position = 50
|
||||
countZero = 0
|
||||
for line in lines:
|
||||
left = line[0] == "L"
|
||||
distance = int(line[1:])
|
||||
if left:
|
||||
distance *= -1
|
||||
position = (position + distance) % 100
|
||||
if position == 0:
|
||||
countZero += 1
|
||||
return countZero
|
||||
|
||||
|
||||
# PART 2
|
||||
|
||||
|
||||
def calc_2(lines):
|
||||
position = 50
|
||||
countZero = 0
|
||||
for line in lines:
|
||||
left = line[0] == "L"
|
||||
distance = int(line[1:])
|
||||
rounds = abs(distance) // 100
|
||||
countZero += rounds
|
||||
distance = distance % 100
|
||||
if left:
|
||||
distance *= -1
|
||||
distanceToZero = position if left else 100 - position
|
||||
passesZero = abs(distance) >= distanceToZero
|
||||
if passesZero and position != 0:
|
||||
countZero += 1
|
||||
position = (position + distance) % 100
|
||||
return countZero
|
||||
|
||||
|
||||
def parse(raw: str):
|
||||
return f.read().strip().splitlines()
|
||||
|
||||
|
||||
with open("./2025/01/train.txt") as f:
|
||||
d = parse(f)
|
||||
print(f"Train 1: {calc_1(d)}")
|
||||
print(f"Train 2: {calc_2(d)}")
|
||||
|
||||
with open("./2025/01/data.txt") as f:
|
||||
d = parse(f)
|
||||
print(f"Actual 1: {calc_1(d)}")
|
||||
print(f"Actual 2: {calc_2(d)}")
|
||||
11
2025/02/Findings.md
Normal file
11
2025/02/Findings.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Day 02
|
||||
|
||||
## Part 1
|
||||
|
||||
Again, quite easy.
|
||||
|
||||
## Part 2
|
||||
|
||||
As the genral rule of thumb in AoC, now lets generalize. I had more of a brute force approach with a few tricks than an actual nice solution tbh.
|
||||
|
||||
Actually finding recurring patterns sounds like something a FFT should be good at.
|
||||
55
2025/02/main.py
Normal file
55
2025/02/main.py
Normal file
@@ -0,0 +1,55 @@
|
||||
def calc_1(ids: list[tuple[int, int]]):
|
||||
invalid = 0
|
||||
for i in ids:
|
||||
for x in range(i[0], i[1] + 1):
|
||||
asStr = str(x)
|
||||
l = len(asStr)
|
||||
isEvenLength = l % 2 == 1
|
||||
if isEvenLength:
|
||||
continue
|
||||
half = l // 2
|
||||
if asStr[:half] == asStr[half:]:
|
||||
invalid += x
|
||||
return invalid
|
||||
|
||||
|
||||
def calc_2(ids: list[tuple[int, int]]):
|
||||
invalid = 0
|
||||
for i in ids:
|
||||
for x in range(i[0], i[1] + 1):
|
||||
s = str(x)
|
||||
l = len(s)
|
||||
for m in range(1, (l // 2) + 1):
|
||||
if l % m != 0:
|
||||
continue
|
||||
first = s[:m]
|
||||
max_multiples = l // m
|
||||
is_invalid = False
|
||||
for offset in range(1, max_multiples):
|
||||
start = offset * m
|
||||
end = start + m
|
||||
if first != s[start:end]:
|
||||
is_invalid = True
|
||||
break
|
||||
if is_invalid:
|
||||
continue
|
||||
invalid += x
|
||||
break
|
||||
return invalid
|
||||
|
||||
|
||||
def parse(raw):
|
||||
ids = raw.read().strip().replace("\n", "").split(",")
|
||||
return [tuple(map(int, (i.split("-")))) for i in ids]
|
||||
|
||||
|
||||
# Run
|
||||
with open("./2025/02/train.txt") as f:
|
||||
d = parse(f)
|
||||
print(f"Train 1: {calc_1(d)}")
|
||||
print(f"Train 2: {calc_2(d)}")
|
||||
|
||||
with open("./2025/02/data.txt") as f:
|
||||
d = parse(f)
|
||||
print(f"Actual 1: {calc_1(d)}")
|
||||
print(f"Actual 2: {calc_2(d)}")
|
||||
5
2025/03/Findings.md
Normal file
5
2025/03/Findings.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Day 02
|
||||
|
||||
## Part 1
|
||||
|
||||
## Part 2
|
||||
34
2025/03/main.py
Normal file
34
2025/03/main.py
Normal file
@@ -0,0 +1,34 @@
|
||||
def calc_1(input):
|
||||
total = 0
|
||||
for line in input:
|
||||
print(line)
|
||||
l = len(line)
|
||||
maximum = 0
|
||||
for a in range(l):
|
||||
for b in range(a + 1, l):
|
||||
x = int(line[a] + line[b])
|
||||
if x > maximum:
|
||||
maximum = x
|
||||
print(line, maximum)
|
||||
total += maximum
|
||||
return total
|
||||
|
||||
|
||||
def calc_2(input):
|
||||
pass
|
||||
|
||||
|
||||
def parse(raw: str):
|
||||
return raw.read().splitlines()
|
||||
|
||||
|
||||
# Run
|
||||
with open("./2025/03/train.txt") as f:
|
||||
d = parse(f)
|
||||
print(f"Train 1: {calc_1(d)}")
|
||||
# print(f"Train 2: {calc_2(d)}")
|
||||
|
||||
with open("./2025/03/data.txt") as f:
|
||||
d = parse(f)
|
||||
print(f"Actual 1: {calc_1(d)}")
|
||||
# print(f"Actual 2: {calc_2(d)}")
|
||||
5
2025/XX/Findings.md
Normal file
5
2025/XX/Findings.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Day 02
|
||||
|
||||
## Part 1
|
||||
|
||||
## Part 2
|
||||
22
2025/XX/main.py
Normal file
22
2025/XX/main.py
Normal file
@@ -0,0 +1,22 @@
|
||||
def calc_1(input):
|
||||
pass
|
||||
|
||||
|
||||
def calc_2(input):
|
||||
pass
|
||||
|
||||
|
||||
def parse(raw: str):
|
||||
return raw
|
||||
|
||||
|
||||
# Run
|
||||
with open("./2025/XX/train.txt") as f:
|
||||
d = parse(f)
|
||||
print(f"Train 1: {calc_1(d)}")
|
||||
print(f"Train 2: {calc_2(d)}")
|
||||
|
||||
with open("./2025/XX/data.txt") as f:
|
||||
d = parse(f)
|
||||
print(f"Actual 1: {calc_1(d)}")
|
||||
print(f"Actual 2: {calc_2(d)}")
|
||||
Reference in New Issue
Block a user