Advent of Code 2023 day 15
12/15/2024, 5:00 AMMarcin Wisniowski
12/15/2024, 6:19 AMMarcin Wisniowski
12/15/2024, 6:19 AMJonathan Kolberg
12/15/2024, 6:53 AMMichael de Kaste
12/15/2024, 6:57 AMJonathan Kolberg
12/15/2024, 6:59 AMMichael de Kaste
12/15/2024, 7:30 AMDan Fingal-Surma
12/15/2024, 7:51 AMDan Fingal-Surma
12/15/2024, 7:51 AMJonathan Kolberg
12/15/2024, 7:53 AMDan Fingal-Surma
12/15/2024, 7:54 AMDan Fingal-Surma
12/15/2024, 7:54 AMDan Fingal-Surma
12/15/2024, 7:54 AMDan Fingal-Surma
12/15/2024, 7:58 AMDan Fingal-Surma
12/15/2024, 7:58 AMDan Fingal-Surma
12/15/2024, 7:59 AMDan Fingal-Surma
12/15/2024, 8:47 AMDan Fingal-Surma
12/15/2024, 8:48 AMDan Fingal-Surma
12/15/2024, 8:48 AMDan Fingal-Surma
12/15/2024, 8:48 AMphldavies
12/15/2024, 11:16 AMSet<Point(x,y)>
but I got there in the end...
year 2024 day 15 warmup (30 iterations) took 9.441068167s
year 2024 day 15 part 1
Default took 36.804841ms 👑: 1421727
year 2024 day 15 part 2
Default took 275.489666ms 👑: 1463160
Max Thiele
12/15/2024, 11:47 AMJakub Gwóźdź
12/15/2024, 12:46 PMDavid
12/15/2024, 2:33 PMJakub Gwóźdź
12/15/2024, 2:34 PMDavid
12/15/2024, 2:39 PMJakub Gwóźdź
12/15/2024, 3:05 PMDavid
12/15/2024, 3:20 PMroman.belov
12/15/2024, 6:19 PMMichael de Kaste
12/15/2024, 6:53 PMcontext(MutableMap<Point, Char>)
fun Set<Point>.nextSet(dir: Point): Set<Point>? = map(dir::plus).flatMapTo(mutableSetOf()) { destination ->
when (get(destination)) {
null -> emptyList()
'#' -> return null
'[' if dir in setOf(NORTH, SOUTH) -> listOf(destination, destination + EAST)
']' if dir in setOf(NORTH, SOUTH) -> listOf(destination, destination + WEST)
else -> listOf(destination)
}
}
Dan Fingal-Surma
12/15/2024, 7:43 PMLuan Tran
12/15/2024, 8:05 PMDavid
12/15/2024, 8:13 PMKai Yuan
12/15/2024, 10:00 PMDan Fingal-Surma
12/15/2024, 10:03 PMDan Fingal-Surma
12/15/2024, 10:10 PM######################
## ##
## [][] ##
## [][][] [] ##
## [] [] [][] ##
## [] [] ##
## [][] ##
## [] ##
## @ ##
######################
Move north
After should be
######################
## [][] ##
## [][] [] ##
## [] [] [] ##
## [][][] [] ##
## [][] ##
## [] ##
## @ ##
## ##
######################
Then start inserting walls in various blank spots that are in the way and make sure nothing movesnerses
12/15/2024, 10:12 PM#########
##..O...#
#...O...#
#..O....#
#.OO....#
#..O.OO.#
#.OO....#
#.#OOO..#
##OOO...#
#O.OO.#.#
#...OO..#
#..O..#.#
#...OO..#
#...@...#
#########
<^<<^><^^>vvvv>>^
Dan Fingal-Surma
12/15/2024, 10:18 PMnerses
12/15/2024, 10:19 PMKai Yuan
12/15/2024, 10:25 PM#..................#
#....[][]..........#
#...[][][]..[].....#
#....[].[].[][]....#
#.....[]..[].......#
#......[][]........#
#.......[].........#
#........@.........#
[after 1 : Up]
#......[]..........#
#...[][]....[].....#
#....[].[].[]......#
#.....[][][].[]....#
#......[][]........#
#.......[].........#
#........@.........#
#..................#
@nerses thank you too! 👍
Now at least I know where to look at.Kai Yuan
12/15/2024, 10:35 PMdistinct()
call was missing.... 💢
I got the 2nd 🌟 after fixing it. Thank you guys..
what a Sunday night!Paul Woitaschek
12/16/2024, 10:38 PMPaul Woitaschek
12/16/2024, 10:39 PMNeil Banman
12/17/2024, 12:10 AMOzioma Ogbe
12/17/2024, 4:25 AMimport utils.Point
import java.io.File
fun main() {
val (input, directions) =
File("input.txt").readText().split("\n\n")
.let {
it[0].let {
it.replace("#", "##").replace(".", "..").replace("@", "@.").replace("O", "[]")
}.split("\n").toMutableList().map { it.toMutableList() }.toMutableList() to it[1].split("\n")
.joinToString("")
}
val directionMap = mapOf(
'^' to Point(-1, 0),
'v' to Point(1, 0),
'<' to Point(0, -1),
'>' to Point(0, 1),
)
var robotPosition = input.mapIndexed { x, chars ->
chars.mapIndexed { y, c ->
if (c == '@') x to y
else null
}
}.flatten().filterNotNull().map { Point(it.first, it.second) }.single()
directions.forEach {
val direction = directionMap[it]!!
val nextPosition = robotPosition.copy(x = robotPosition.x + direction.x, y = robotPosition.y + direction.y)
val inputCopy = input.map { it.map { it }.toMutableList() }.toMutableList()
val result = if (direction.x != 0 && input.getOrNull(nextPosition.x)?.getOrNull(nextPosition.y)
.let { it == ']' || it == '[' }
) {
input.getOrNull(nextPosition.x)!!.getOrNull(nextPosition.y)!!.let {
(if (it == '[') proceed(nextPosition.copy(y = nextPosition.y + 1), input, direction)
else proceed(nextPosition.copy(y = nextPosition.y - 1), input, direction)) && proceed(
nextPosition, input, direction
)
}
} else {
proceed(nextPosition, input, direction)
}
if (result) {
input[robotPosition.x][robotPosition.y] = '.'
robotPosition = nextPosition
input[robotPosition.x][robotPosition.y] = '@'
} else {
inputCopy.forEachIndexed { x, chars -> chars.forEachIndexed { y, c -> input[x][y] = c } }
}
}
input.mapIndexed { x, chars ->
chars.mapIndexed { y, c ->
if (c == '[') (100 * x + y).toLong() else 0L
}.sum()
}.sum().also(::println)
}
fun proceed(
currentPosition: Point,
input: MutableList<MutableList<Char>>,
direction: Point
): Boolean {
val nextPosition = currentPosition.copy(
x = currentPosition.x + direction.x,
y = currentPosition.y + direction.y
)
return when (input[currentPosition.x][currentPosition.y]) {
'#' -> false
'[', ']' -> {
(if (direction.x != 0 && input.getOrNull(nextPosition.x)?.getOrNull(nextPosition.y)
.let { it == ']' || it == '[' }
) {
input.getOrNull(nextPosition.x)!!.getOrNull(nextPosition.y)!!.let {
(if (it == '[') proceed(nextPosition.copy(y = nextPosition.y + 1), input, direction)
else proceed(nextPosition.copy(y = nextPosition.y - 1), input, direction)) && proceed(
nextPosition, input, direction
)
}
} else {
proceed(nextPosition, input, direction)
}).apply {
if (this) {
input[nextPosition.x][nextPosition.y] = input[currentPosition.x][currentPosition.y]
input[currentPosition.x][currentPosition.y] = '.'
}
}
}
'O' -> {
proceed(
nextPosition, input, direction
).apply {
if (this) input[nextPosition.x][nextPosition.y] = input[currentPosition.x][currentPosition.y]
}
}
'.' -> true
else -> error("invalid state")
}
}
ephemient
12/17/2024, 9:31 PM