Advent of Code 2023 day 1
12/01/2025, 5:00 AMMarcin Wisniowski
12/01/2025, 5:20 AMMarcin Wisniowski
12/01/2025, 5:20 AMKroppeb
12/01/2025, 5:26 AMMarcin Wisniowski
12/01/2025, 5:29 AMKroppeb
12/01/2025, 5:32 AMKroppeb
12/01/2025, 5:33 AMKroppeb
12/01/2025, 5:34 AMKroppeb
12/01/2025, 5:37 AMKroppeb
12/01/2025, 5:37 AMJakub Gwóźdź
12/01/2025, 5:44 AMprivate 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
}Michael de Kaste
12/01/2025, 5:57 AMMichael de Kaste
12/01/2025, 6:12 AMy9san9
12/01/2025, 6:24 AMy9san9
12/01/2025, 6:31 AMacc == 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)
Norbert Kiesel
12/01/2025, 6:43 AMfor (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
}phldavies
12/01/2025, 8:02 AMephemient
12/01/2025, 8:33 AMDan Fingal-Surma
12/01/2025, 8:37 AMephemient
12/01/2025, 8:38 AMIntProgression.fromClosedRange(pos + rotation.sign, pos + rotation, rotation.sign).count { it % 100 == 0 }
to compare against… I'd have like to have written
pos + rotation.sign .. pos.rotation step pos.sign
but using a negative step like that isn't permittedAnirudh
12/01/2025, 8:59 AMgenerateSequence(seed) generates the seed as the first value of the seq; fixed with a drop(1) after wasting time debugging output/intermediate stateAnirudh
12/01/2025, 9:00 AMrunningFold 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.Jakub Gwóźdź
12/01/2025, 9:03 AMturns): zeros += (prev + turns) / 100
for turning left (negative turns ) : zeros += ((100 - prev) % 100 - turns) / 100Andriy
12/01/2025, 10:43 AMif (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)?Jaap Beetstra
12/01/2025, 10:43 AMfun 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
}Andriy
12/01/2025, 11:17 AMsolve function impl?Marcin Wisniowski
12/01/2025, 11:25 AMAndriy
12/01/2025, 11:25 AMAdventOfCode class impl?Andriy
12/01/2025, 11:26 AMPuzDSL impl?phldavies
12/01/2025, 11:27 AMMichael de Kaste
12/01/2025, 11:40 AMtheapache64
12/01/2025, 2:04 PMKarloti
12/01/2025, 3:13 PMJakub Gwóźdź
12/01/2025, 3:42 PMphldavies
12/01/2025, 4:09 PM0x434C49434B -> "CLICK"bj0
12/01/2025, 4:40 PMJakub Gwóźdź
12/01/2025, 4:42 PMbj0
12/01/2025, 5:19 PMrenatomrcosta
12/01/2025, 9:43 PMkingsley
12/02/2025, 12:57 AMdenis
12/02/2025, 1:58 AMNeil Banman
12/02/2025, 3:42 AMEdgar Avuzi
12/02/2025, 4:00 AMEdgar Avuzi
12/02/2025, 4:43 AMmod as initially done by MarcinEdgar Avuzi
12/04/2025, 7:53 AM