<Advent of Code 2025 day 1> (spoilers) :thread:
# advent-of-code
a
m
Part 1
💡 2
Part 2
💡 1
k
I can't believe I messed up so bad
😅 1
m
I wanted to do something sensible for part 2, got 2 wrong answers, and reverted back to just incrementing the dial one by one. 😄
👍 1
🙃 2
same 2
k
I missed that I had to start at 50 (apparently it wasn't highlighted) and my answer was only 34 so I assumed I was supposed to count each time it passed over 0, even during rotations, so then I was trying to figure out why my accidental (still very broken) part 2 solution didn't work for part 1
And then I didn't save any time in part 2 because I tried to use maths instead of iterating one by one and got sunken cost fallacied
same 1
Here is my part 2. I don't know why the maths is what it is. I just stepped trough the example case and checked where my edgecases were wrong
Ah, this is how I should have fixed the off by one. Makes more sense
I really love my "modulo range util"
j
OH MY GOD I could also do the "decrement by one" for part2 and get the correct answer, instead I wasted like 20 minutes trying to figure out the correct formula 😆
Copy code
private fun solve(data: String, counterOp: (prev: Int, turns: Int, next: Int) -> Int): Int =
    data.trim().lines().fold(50 to 0) { (prev, zeros), line ->
        val turns = if (line.first() == 'R') line.drop(1).toInt() else -line.drop(1).toInt()
        val next = (prev + turns).mod(100)
        next to zeros + counterOp(prev, turns, next)
    }.second

fun part1(data: String) = solve(data) { _, _, next ->
    if (next == 0) 1 else 0
}

fun part2(data: String) = solve(data) { prev, turns, next ->
    (if (turns > 0) prev + turns else (100 - prev) % 100 - turns) / 100
}
m
embarrassing first day for me. 🫥
same 7
After some cleanup; really dont like how I had to handle the 'acc == 0 and direction is negative' seperately
K 1
y
I decided to go with no build system and explore Kotlin Scripting pros and cons: https://github.com/y9san9/aoc25/blob/main/day1.part2.main.kts
👍 1
acc == 0 and direction is negative
@Michael de Kaste had the same if in the first implementation. But changed it later to iteration over all the steps since I thought it might be enough for day 1 (I didn't prepare myself for thinking)
n
I of course also first struggled with the "negative number but started at 0". My solution ended up using
Copy code
for (n in parse(input)) {
            zeros += abs(n) / 100
            num += n % 100
            if (num == 0 || num >= 100 || num < 0 && num != n % 100) {
                zeros++
            }
            num = (num + 100) % 100
        }
p
I only made the mistake once of attempting to calculate passes by zero on part 2 and fell back to something my brain could cope with at 5am.
e
also had to scan the range to get the right value for part 2, took a while to think and simplify afterwards
d
I actually solved part 2 with a for-loop and vars, but it cleaned up nicely: https://github.com/dfings/advent-of-code/blob/main/src/2025/problem_1.main.kts
e
I used
Copy code
IntProgression.fromClosedRange(pos + rotation.sign, pos + rotation, rotation.sign).count { it % 100 == 0 }
to compare against… I'd have like to have written
Copy code
pos + rotation.sign .. pos.rotation step pos.sign
but using a negative step like that isn't permitted
a
my off-by-one error happened with the positions-sequence in part 2. because
generateSequence(seed)
generates the seed as the first value of the seq; fixed with a
drop(1)
after wasting time debugging output/intermediate state
for part 1 I used
runningFold
with
count { it == 0 }
but for part 2 (using incremental approach) I used just
fold
with
var zeroes = 0
to count. seems dirty to use
fold
for the side-effects. might change it to generateSeq.
j
for turning right (positive
turns
):
zeros += (prev + turns) / 100
for turning left (negative
turns
) :
zeros += ((100 - prev) % 100 - turns) / 100
a
Just implemented my solution and via Kotlin Notebook. Interesting that the rough solution works for the both Day 1 parts (only code
Copy code
if (position == 0) count++
need to be places in appropriate place 🙂) Guys, do you know how to disable a cell from execution (and not to use comments for this)?
j
This feels way too complicated for a day 1
Copy code
fun countClicks(position: Int, newPosition: Int): Int =
    when {
        newPosition >= 100 -> newPosition / 100
        newPosition < 0 && position == 0 -> -newPosition / 100
        newPosition < 0 -> 1 + (-newPosition / 100)
        position != 0 && newPosition == 0 -> 1
        else -> 0
    }
a
@Marcin Wisniowski could you share your AoC infrastructure
solve
function impl?
m
a
@Michael de Kaste what is your
AdventOfCode
class impl?
@phldavies what is your
PuzDSL
impl?
p
short answer: far too over-engineered 🙂
😀 1
m
I use a small builder DSL class
👍 1
t
this is not a spoiler thread. this thread is more like “you weren’t the only one who messed up..you can go back and fix things peacefully now” thread 😄
😄 3
❤️ 2
j
Good the part2 hasn't a sentence like "you also notice that every rotation needs to be repeated 0x434C49434B times" 😆
p
I did like that
0x434C49434B
->
"CLICK"
K 3
b
dang I assumed iterating and checking every click would take too long but a lot of people seem to have fallen back on that and it worked just fine. i just banged my head against the "check how many multiples" route until i finally realized i had to special case starting at 0
same 1
j
Yeah Imagine if there was no 0-case in the example. I'd be still on part 2, probably 🙂
b
finally cleaned up
r
Super late to the party, just kept mine simple and dumb with some iteration and maybe too overzealous oop https://github.com/renatomrcosta/adventofcode/blob/main/src/main/kotlin/aoc2025/day01/day01.kt
d
day1.png
n
Nice to see familiar names/faces. Also nice to see that I wasn't the only one to stumble a bit on the counting of leftward clicks.
e
A bit verbose but explicit
Or just using
mod
as initially done by Marcin
🔥 1
For Day 1 Part 2 solution using declarative-like style