Advent of Code 2021 day 8
12/08/2021, 5:00 AMDan Fingal-Surma
12/08/2021, 5:22 AMDan Fingal-Surma
12/08/2021, 5:33 AMDavid Whittaker
12/08/2021, 5:38 AMDan Fingal-Surma
12/08/2021, 5:45 AMDan Fingal-Surma
12/08/2021, 6:37 AMknthmn
12/08/2021, 6:38 AMMarcin Wisniowski
12/08/2021, 6:50 AMDavid Whittaker
12/08/2021, 7:14 AMelizarov
12/08/2021, 7:58 AMs.chunked(1)
can be simplified to s.toList()
Marcin Wisniowski
12/08/2021, 8:12 AMList<Char>
, where chunked(1)
returns a List<String>
. Of course I could make the solution work with Char
but the behavior is different.elizarov
12/08/2021, 8:13 AMMarcin Wisniowski
12/08/2021, 8:14 AMephemient
12/08/2021, 8:19 AM.filter(predicate).size == .count(predicate)
ephemient
12/08/2021, 8:21 AMephemient
12/08/2021, 8:24 AMMarcin Wisniowski
12/08/2021, 8:24 AMDan Fingal-Surma
12/08/2021, 8:55 AMDan Fingal-Surma
12/08/2021, 8:57 AMPitel
12/08/2021, 8:58 AMpermuations()
method! And it takes 12 seconds on Raspberry Pi 4.Paul Woitaschek
12/08/2021, 9:53 AMPaul Woitaschek
12/08/2021, 9:53 AMPaul Woitaschek
12/08/2021, 9:53 AMphldavies
12/08/2021, 10:36 AMelizarov
12/08/2021, 10:37 AMpermutations
method. No one have ever needed it in any real-life code. We could not figure out why on earth C++ stdlib has methods to generate permutations.Pitel
12/08/2021, 10:45 AMelizarov
12/08/2021, 10:46 AMMarcin Wisniowski
12/08/2021, 10:49 AMmedian()
for lists is a missing method that I actually needed in real world code multiple times (and average()
exists). Permutations? Only ever in puzzles. (My point is that if we don't need something as simple and useful as median()
, then we certainly don't need permutations either).Paul Woitaschek
12/08/2021, 11:07 AMelizarov
12/08/2021, 12:23 PMelizarov
12/08/2021, 12:26 PMmedian()
in https://youtrack.jetbrains.com/issue/KT-50138Marcin Wisniowski
12/08/2021, 12:27 PMTies
12/08/2021, 1:03 PMcak
12/08/2021, 1:06 PMMichael de Kaste
12/08/2021, 3:12 PMobject Day8 : Challenge() {
val parsed = input.lines().map { it.split(" | ").map { it.split(" ").map { it.toSortedSet() } } }
override fun part1() = parsed.sumOf { (_, output) -> output.map{ it.size }.count(listOf(2, 4, 3, 7)::contains) }
override fun part2() = parsed.sumOf { (input, output) ->
val wires = Array<Set<Char>>(10) { emptySet() }.apply {
this[1] = input.single { it.size == 2 }
this[4] = input.single { it.size == 4 }
this[7] = input.single { it.size == 3 }
this[8] = input.single { it.size == 7 }
this[3] = input.single { it.size == 5 && this[7] in it }
this[2] = input.single { it.size == 5 && this[8] - this[4] in it }
this[5] = input.single { it.size == 5 && this[8] - this[2] in it }
this[9] = input.single { it.size == 6 && this[3] in it }
this[6] = input.single { it.size == 6 && this[8] - this[1] in it }
this[0] = input.single { it.size == 6 && this[5] !in it }
}
output.fold(0L) { int, set -> int * 10 + wires.indexOf(set) }
}
operator fun <T> Set<T>.contains(other: Set<T>) = containsAll(other)
}
Paul Woitaschek
12/08/2021, 5:13 PMDan Fingal-Surma
12/08/2021, 5:18 PMephemient
12/08/2021, 5:22 PMPoisonedYouth
12/08/2021, 6:07 PMphldavies
12/08/2021, 6:40 PMKiet
12/09/2021, 5:37 AM