Advent of Code 2021 day 18
12/18/2021, 5:00 AMelizarov
12/18/2021, 6:43 AMJakub Gwóźdź
12/18/2021, 7:38 AMelizarov
12/18/2021, 8:09 AMJakub Gwóźdź
12/18/2021, 8:21 AMelizarov
12/18/2021, 8:25 AMJakub Gwóźdź
12/18/2021, 8:38 AMKiet
12/18/2021, 9:05 AMnkiesel
12/18/2021, 9:35 AMnkiesel
12/18/2021, 9:38 AMval mb = Regex("""(.+?)(\d+)([^\d]+)""").matchEntire(before)
if (mb == null) {
append(before)
} else {
append("${mb.groupValues[1]}${mb.groupValues[2].toInt() + left.toInt()}${mb.groupValues[3]}")
}
(where left
is a match from the regex matching the beginning of the level-5)nkiesel
12/18/2021, 9:39 AMnkiesel
12/18/2021, 9:56 AMRegex
. But the replaceFirst
only exists for simple replacement strings.nkiesel
12/18/2021, 10:13 AMnkiesel
12/18/2021, 10:17 AMnkiesel
12/18/2021, 10:26 AMelizarov
12/18/2021, 10:27 AMbuildList {
for (i in a.indices) for (j in a.indices) if (i != j)
add(add(a[i], a[j]).magnitude())
}.maxOrNull()!!
nkiesel
12/18/2021, 10:38 AMa.forEachIndexed { i1, f1 -> a.forEachIndexed { i2, f2 -> ...
?
BTW: I created a infix operator fun plus(other: Fish) = Fish("[$this,$other]").reduced()
to use add((a[i] + a[j]).magnitude())
nkiesel
12/18/2021, 10:54 AMinput.map { Fish(it) }.reduce { acc, fish -> acc + fish }
. Why can't I use input.sumOf { Fish(it) }
?Jakub Gwóźdź
12/18/2021, 11:05 AMl.flatMap { l1 -> l.map { l2 -> addition(l1, l2) } }
.maxOf { it.magnitude() }
l
- list of inputsnkiesel
12/18/2021, 11:16 AMnkiesel
12/18/2021, 11:18 AMval fish = input.mapIndexed { i, f -> i to Fish(f) }.toMap()
return fish.flatMap { (i, f) -> (fish - i).let { g -> g.values.map { f + it } } }.maxOf { it.magnitude() }
Kiet
12/18/2021, 11:27 AMKiet
12/18/2021, 11:28 AMparseSnailNode
for detailsMarcin Wisniowski
12/18/2021, 12:03 PMephemient
12/18/2021, 12:45 PMephemient
12/18/2021, 1:11 PMMichael Böiers
12/18/2021, 4:46 PMDan Fingal-Surma
12/18/2021, 6:41 PMDan Fingal-Surma
12/18/2021, 7:21 PMDan Fingal-Surma
12/18/2021, 7:41 PMDan Fingal-Surma
12/18/2021, 7:52 PMnkiesel
12/18/2021, 9:03 PMephemient
12/18/2021, 9:04 PMephemient
12/18/2021, 9:06 PMfun MutableList<T>.splice(IntRange, Iterable<T>)
is annoying thoughnkiesel
12/18/2021, 9:27 PMMichael Böiers
12/18/2021, 9:28 PMMichael Böiers
12/18/2021, 9:45 PMDan Fingal-Surma
12/18/2021, 9:52 PMDan Fingal-Surma
12/18/2021, 9:53 PMMichael Böiers
12/18/2021, 10:41 PMDan Fingal-Surma
12/18/2021, 10:54 PMDan Fingal-Surma
12/19/2021, 12:14 AMinfix fun <T, U> Sequence<T>.cartesianProduct(other: Sequence<U>): Sequence<Pair<T, U>> =
this.flatMap { i -> other.map { j -> i to j } }
infix fun <T, U> Iterable<T>.cartesianProduct(other: Iterable<U>): Sequence<Pair<T, U>> =
this.asSequence() cartesianProduct other.asSequence()
Kiet
12/19/2021, 7:28 AMJintin
12/19/2021, 9:37 AMPaul Woitaschek
12/19/2021, 5:42 PMphldavies
12/19/2021, 9:37 PMphldavies
12/19/2021, 9:38 PMNate Ridderman
01/02/2022, 2:40 PMbuildList {
for (i in 1 until a.size) for (j in 0 until i-1)
add(Pair(a[i], a[j]))
}
ephemient
01/02/2022, 3:45 PMbuildList { a.forEachIndexed { i, x -> a.subList(0, i).mapTo(this, x::to) } }
although this particular puzzle needs all n * (n - 1)
pairs, not just half of themNate Ridderman
01/02/2022, 5:14 PM