Edgars
12/09/2019, 2:05 PMIntCode<T : Number>
. Need to refactor it for Day 7 anyway.todd.ginsberg
12/09/2019, 2:14 PMtodd.ginsberg
12/09/2019, 5:31 PMtodd.ginsberg
12/09/2019, 11:44 PMtodd.ginsberg
12/10/2019, 12:42 AMKroppeb
12/10/2019, 10:07 AMChristoph Baudson
12/10/2019, 11:48 AMtodd.ginsberg
12/10/2019, 6:03 PMCollection<List<T>>
into a List<T>
by doing round-robin (so, [ [A, D], [B, E], [C] ]
becomes [A, B, C, D, E]
) and used that for part 2.Rostyslav
12/10/2019, 6:39 PMtodd.ginsberg
12/10/2019, 11:43 PMtodd.ginsberg
12/11/2019, 2:30 PMJoris PZ
12/11/2019, 6:50 PMtodd.ginsberg
12/11/2019, 8:21 PMEvan R.
12/11/2019, 8:55 PMmarstran
12/12/2019, 2:42 PMtodd.ginsberg
12/12/2019, 4:40 PMEdgars
12/12/2019, 6:04 PMJoris PZ
12/12/2019, 9:28 PMtodd.ginsberg
12/13/2019, 12:13 AMJakub Gwóźdź
12/13/2019, 11:28 AM.receive()
is explicitly called and b) only after another channel (output from the Intcode) has been completely processed.
I failed to do it, so instead I created a wrapper that does something like
override suspend fun receive(): BigInteger {
while (!output.isEmpty) {
val x = output.receive()
// ... process x
}
return something
}
But I think I'm missing some point here and it could be more elegantEdgars
12/13/2019, 2:06 PMJoris PZ
12/13/2019, 2:13 PMChristoph Baudson
12/13/2019, 5:31 PMtodd.ginsberg
12/13/2019, 10:42 PMRostyslav
12/14/2019, 12:08 PMkarelpeeters
12/14/2019, 6:16 PMKroppeb
12/15/2019, 6:26 AMRostyslav
12/15/2019, 12:05 PMRostyslav
12/16/2019, 11:55 AMKroppeb
12/17/2019, 5:41 AMKroppeb
12/17/2019, 5:41 AMsplit()
so I decided to convert to an actual string which took quite some time to get right.
output.toList().joinToString(separator = "") { it.toChar().toString() }.split("\n").map{it.map{it}}
Rostyslav
12/17/2019, 7:30 AMoutput.map { it.toChar()}.joinToString("").split("\n").map { it.toList() }
Edgars
12/17/2019, 9:04 AMJoris PZ
12/17/2019, 12:19 PM.lines()
instead of .split("\n")
:
.map { it.toChar() }.toList().joinToString("").lines()
Kroppeb
12/17/2019, 12:23 PMsplitLines
or somethingJakub Gwóźdź
12/17/2019, 2:56 PMChannel
s for I/O, so I added a Flow
for it and transform it like this:
@Suppress("BlockingMethodInNonBlockingContext")
private fun Flow<Char>.fullLines(): Flow<String> = flow {
val builder = StringBuilder()
collect {
when (it) {
'\n' -> emit(builder.toString()).also { builder.clear() }
else -> builder.append(it)
}
}
}
this approach has some flaws (e.g. just forgets last line without any \n
at the end) but is good enough for day17 🙂Joris PZ
12/17/2019, 3:46 PMlaunch {
while (!stdout.isClosedForReceive) {
stdout.receive().also { print(if (it < 255) it.toChar() else "Part 2: $it") }
}
}