Nir
12/14/2021, 7:50 PMMutableMap<T, Long>
is okay-ish for this, but incrementing feels very awkward
myCounts[something] = myCounts.getOrDefault(something, 0) + numberFound
I've generally found that updating state in maps can be a bit annoying so I do have a general helper function (which I think would be worth having in stdlib tbh)
fun <K, V> MutableMap<K, V>.update(k: K, transform: (V?) -> V) = set(k, transform(get(k)))
So it becomes
myCounts.update(k) { (it ?: 0) + numberFound
But still, end up repeating quite a bit. If there isn't a better way then I may just have a dedicated Counter (a la python) and possibly deal with both things with one stoneAdvent of Code 2021 day 15
12/15/2021, 5:00 AMilya.gorbunov
12/15/2021, 7:20 AMAdvent of Code 2021 day 16
12/16/2021, 5:00 AMMichael de Kaste
12/16/2021, 6:29 AMval packetVersion = stringbuilder.removeRange(0..2).toLong(2)
I guessed wrong this morning 😉Endre Deak
12/16/2021, 4:56 PM// s is my input representation and once a portion is processed, I remove that portion
val sub = mutableListOf<Packet>()
while(!s.isEmpty()) {
sub.add(processPacket(s))
}
return sub
Advent of Code 2021 day 17
12/17/2021, 5:00 AMAdvent of Code 2021 day 18
12/18/2021, 5:00 AMKiet
12/18/2021, 10:17 AMKiet
12/19/2021, 4:28 AMvar explosionResult = result.explode(0)
while (explosionResult.explosionOcurred) {
explosionResult = result.explode(0)
}
Advent of Code 2021 day 19
12/19/2021, 5:00 AMMichael de Kaste
12/19/2021, 12:42 PMfunctionThatReturnsNullable() ?: doOnNull() followed by continue
Nir
12/19/2021, 6:23 PMisEmpty
as an extension property with size == 0
seems fine...Advent of Code 2021 day 20
12/20/2021, 5:00 AMDavid Whittaker
12/20/2021, 6:09 PMDavid Whittaker
12/21/2021, 2:13 AMAdvent of Code 2021 day 21
12/21/2021, 5:00 AMAdvent of Code 2021 day 22
12/22/2021, 5:00 AMKiet
12/22/2021, 6:25 AMAdvent of Code 2021 day 23
12/23/2021, 5:00 AMAdvent of Code 2021 day 24
12/24/2021, 5:00 AMAdvent of Code 2021 day 25
12/25/2021, 5:00 AMtodd.ginsberg
01/07/2022, 1:05 PMKsenia Shneyveys
01/27/2022, 5:04 PMMikael Alfredsson
02/06/2022, 8:56 AMDavid Whittaker
03/01/2022, 7:03 AMPaul Woitaschek
03/15/2022, 4:26 PMJakub Gwóźdź
10/30/2022, 5:11 AMKroppeb
11/11/2022, 5:40 PMJakub Gwóźdź
11/23/2022, 4:45 AM