Advent of Code 2021 day 23
12/23/2022, 5:00 AMSergei Petunin
12/23/2022, 5:51 AMMarcin Wisniowski
12/23/2022, 5:56 AMJonathan Kolberg
12/23/2022, 6:56 AMJan Durovec
12/23/2022, 6:56 AMJonathan Kolberg
12/23/2022, 6:58 AMrkechols
12/23/2022, 7:17 AMJonathan Kolberg
12/23/2022, 7:22 AMcorneil
12/23/2022, 7:33 AMJan Durovec
12/23/2022, 8:00 AMVlad Petrushkevich
12/23/2022, 8:03 AMIf no other Elves are in one of those eight positions, the Elf does not do anything during this round.
Jonathan Kolberg
12/23/2022, 8:44 AMOzioma Ogbe
12/23/2022, 9:54 AMOzioma Ogbe
12/23/2022, 9:58 AMOlaf Gottschalk
12/23/2022, 10:00 AMOzioma Ogbe
12/23/2022, 10:00 AMritesh
12/23/2022, 10:38 AMFredrik Rødland
12/23/2022, 10:53 AMcorneil
12/23/2022, 11:39 AMFredrik Rødland
12/23/2022, 11:53 AMcorneil
12/23/2022, 11:57 AMMichael Böiers
12/23/2022, 12:04 PMJakub Gwóźdź
12/23/2022, 1:17 PMephemient
12/23/2022, 3:11 PMephemient
12/23/2022, 3:11 PMphldavies
12/23/2022, 3:14 PMphldavies
12/23/2022, 3:16 PMgroupingBy/aggregate
approach for the rounds 👍Michael Böiers
12/23/2022, 3:20 PMephemient
12/23/2022, 3:23 PMdata class IntPair(val first: Int, val second: Int)
just to get rid of the boxing that Pair<Int, Int>
would doephemient
12/23/2022, 3:23 PMIndexedValue
when I need to attach an Int
to something, even though it's not really "indexed" by itephemient
12/23/2022, 6:36 PMephemient
12/23/2022, 6:39 PMlet ((Min minX, Max maxX), (Min minY, Max maxY)) = foldMap ((Min &&& Max) *** (Min &&& Max)) points
but in Kotlin I'd either have to do it in multiple passes
val minX = points.minOf { (x, _) -> x }
val maxX = points.maxOf { (x, _) -> x }
val minY = points.minOf { (_, y) -> y }
val maxY = points.maxOf { (_, y) -> y }
or with imperative code
var minX = Int.MAX_VALUE
var maxX = Int.MIN_VALUE
var minY = Int.MAX_VALUE
var maxY = Int.MIN_VALUE
for ((x, y) in points) {
minX = minOf(minX, x)
maxX = maxOf(maxX, x)
minY = minOf(minY, y)
maxY = maxOf(maxY, y)
}
both of which I've written with typo'ed errors multiple times alreadyJonathan Kolberg
12/23/2022, 6:46 PMcorneil
12/23/2022, 7:52 PMdata class<T>MinMax(val min: T, val max: T)
corneil
12/23/2022, 7:53 PMphldavies
12/23/2022, 7:53 PMJonathan Kolberg
12/23/2022, 8:42 PMnextTurnOFfsets
todd.ginsberg
12/23/2022, 8:44 PMephemient
12/23/2022, 8:44 PMI experimented with generateSequence but didn’t end up liking how it lookedany reason? I think
.zipWithNext().indexOfFirst { (prev, cur) -> prev == cur } + 1
is pretty goodtodd.ginsberg
12/23/2022, 8:47 PMphldavies
12/23/2022, 8:49 PMsequence{}
in an .ifEmpty { return@sequence }
to end the sequence letting me just .count()
.phldavies
12/23/2022, 8:50 PMephemient
12/23/2022, 8:52 PMscan
(aka runningFold
, but I'm more accustomed to the scan
name as it's more common in other langauges) over a sequence of directions, so part moving the elves doesn't have to keep track of thatphldavies
12/23/2022, 8:53 PMephemient
12/23/2022, 8:53 PMtodd.ginsberg
12/23/2022, 8:55 PMphldavies
12/23/2022, 8:57 PMephemient
12/23/2022, 8:57 PMcycle(("NSWE", "SWEN", "WENS", "ENSW"))
which I could have ported back to Kotlin, if I wanted to be type-unsafe :Dtodd.ginsberg
12/23/2022, 8:59 PMephemient
12/23/2022, 9:09 PMrkechols
12/23/2022, 11:28 PMnkiesel
12/24/2022, 3:42 AMCollection<Int>.toRange(): IntRange
might do the trick.elizarov
12/24/2022, 7:23 AMritesh
12/24/2022, 3:37 PMSet<Position>
works, i had a hard time, when i was using grids, switching to sets of positions tracking elves made it much simpler.Ozioma Ogbe
12/24/2022, 3:56 PMephemient
12/24/2022, 3:57 PMphldavies
12/24/2022, 3:58 PMget(x, y)
operator.ephemient
12/24/2022, 4:00 PMSet<IntPair>
on 23 because it's less work, but if I go back to speed it up, I'll probably switch to some packed bit representation so that I can scan over it with a LUT