mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2025-12-14 05:44:59 +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)}")
|
||||
Reference in New Issue
Block a user