Advent of Code 2021 day 22
12/22/2022, 5:00 AMSergei Petunin
12/22/2022, 6:00 AMDavid Whittaker
12/22/2022, 6:15 AMJan Durovec
12/22/2022, 6:18 AMMarcin Wisniowski
12/22/2022, 6:34 AMBin Wang
12/22/2022, 6:37 AMJan Durovec
12/22/2022, 6:38 AMOlaf Gottschalk
12/22/2022, 6:46 AMJan Durovec
12/22/2022, 6:50 AM##
#
##
#
Jonathan Kolberg
12/22/2022, 7:38 AMelizarov
12/22/2022, 7:39 AMelizarov
12/22/2022, 7:41 AMelizarov
12/22/2022, 7:42 AMJonathan Kolberg
12/22/2022, 7:47 AMprivate tailrec fun parseInstructionsHelper(
restInput: String,
currentList: List<Instruction>
): List<Instruction>
elizarov
12/22/2022, 7:55 AMJonathan Kolberg
12/22/2022, 7:58 AMJan Durovec
12/22/2022, 7:59 AMelizarov
12/22/2022, 8:00 AMJonathan Kolberg
12/22/2022, 8:06 AMJan Durovec
12/22/2022, 8:12 AMJan Durovec
12/22/2022, 8:12 AMrkechols
12/22/2022, 8:25 AM\d+|[LR]
and had it find all matches.ritesh
12/22/2022, 8:49 AMlist of list
(which is eating up extra blank spaces), i am sure there must be better approaches when it comes to forming the data structure.Jan Durovec
12/22/2022, 9:31 AMSet<Pair<Int,Int>>
however, in this case I just left it as List<String>
which I read from the file and had in memory anyway and just checked input[row][col] == '#'
Marcin Wisniowski
12/22/2022, 10:31 AMJoffrey
12/22/2022, 11:59 AMSergei Petunin
12/22/2022, 12:27 PMJonathan Kolberg
12/22/2022, 12:52 PMvariable::getValue
, then you do not need !!
Michael Böiers
12/22/2022, 12:58 PMSergei Petunin
12/22/2022, 12:59 PMMichael Böiers
12/22/2022, 1:53 PMval instructions: List<Any> = lines.last().asSequence().fold(mutableListOf<String>()) { acc, c ->
acc.apply {
when {
c.isDigit() -> {
if (isEmpty() || last().toIntOrNull() == null) add("")
set(lastIndex, last() + c)
}
else -> add(c.toString())
}
}
}.map { it.toIntOrNull() ?: it }.toList()
phldavies
12/22/2022, 5:50 PMprivate val netLinks: Map<String, String> = mapOf(
"--0-:123-:--45" to "0DU3;0LU2;0RR5;0UU1;1DD4;1LD5;1RL2;2DL4;2RL3;3DU4;3RU5;4RL5", // example
"-01:-2-:34-:5--" to "0DU2;0LL3;0RL1;0UL5;1DR2;1RR4;1UD5;2DU4;2LU3;3DU5;3RL4;4DR5", // input
)
Riccardo Lippolis
12/22/2022, 6:44 PMRegex("""\d+|[LR]""").findAll(lines.last()).map { it.value }
ephemient
12/22/2022, 6:44 PMephemient
12/22/2022, 6:44 PMephemient
12/22/2022, 6:46 PMephemient
12/22/2022, 6:47 PMRiccardo Lippolis
12/22/2022, 6:47 PMbabel
12/22/2022, 6:50 PMunpairedEdges
that’s wild @ephemient!babel
12/22/2022, 6:50 PMphldavies
12/22/2022, 10:42 PMPaul Woitaschek
12/22/2022, 11:26 PMPaul Woitaschek
12/22/2022, 11:26 PMphldavies
12/22/2022, 11:28 PMOzioma Ogbe
12/23/2022, 2:26 AMelizarov
12/23/2022, 6:14 AMMarcin Wisniowski
12/23/2022, 6:19 AMMarcin Wisniowski
12/23/2022, 6:23 AMLinkedHashMap<F, Int>()
, rather than the idiomatic (I think) mutableMapOf()
?ritesh
12/23/2022, 7:28 AM[row][col] != '.'
- assuming even tiles are blockers, simple change was to just check for [row][col] != '#'
It was passing for testInput but not for real input, until i changed it to [row][col] != '#'
elizarov
12/23/2022, 8:19 AMxxxOf()
functions read without parameters. Anyway, I rewrote it without a mutable set and without manual counting. It looks nicer using groupingBy { it }.eachCount()
Jon Senchyna
12/25/2022, 6:04 PM