My day 17: <https://github.com/jorispz/aoc-2019/bl...
# advent-of-code
j
My day 17: https://github.com/jorispz/aoc-2019/blob/master/src/commonMain/kotlin/day17/p17.kt I went low-tech and did part 2 by hand using Excel, given the small world map it seemed a lot quicker than creating an algorithm
m
I also wonder if all possible paths will be reducable to 3 functions. I just found the first path using a depth-first search, and it happened to work.
k
The generater probably starts with 3 functions and and a main and generates the map using that. Probably also a check preventing a path to go over itself (still allowing crossing)
m
Probably, but that will only ensure that at least 1 path can be written as 3 functions. But there are multiple other paths that may not have the same property (depending if you go left or right in an intersection for example).
k
the following algo seems to always visit all points once, and intersections twice:
Copy code
while(True){
    when{
        canMoveForwards() -> moveForwards()
        canMoveLeft() -> turnLeft()
        canMoveRight() -> turnRight()
        else -> break //finished
    }
}
m
It might reach a dead end though (assuming the “canMove” function is just checking if the next field is a scaffold).
k
It won't
m
Why?
k
Look at your scaffold
m
What if the first turn to the left ends up in a dead end?
k
?
m
Let me create an example. 2 sec.
If the map looks like this, then you will reach the dead end before making the loop:
Copy code
...........
.#########.
.#.......#.
.#..#....#.
.#########.
....#......
....#......
....###^...
k
mmh
Yeah i don't think it will do that
m
But then you’re assuming things about the input 😛 I was wondering if it would work in general.
k
Yeah, but assuming things about the input is part of the game
It's quite easy to make a checker for that
m
Sure, but it was not what I asked.
k
I'm pretty sure the input is crafted in a way that makes the desired path quite obvious. aka don't turn if you don't have to
m
Would be more impressive if they managed to make every path reducible to 3 functions 😛
I actually checked now. I found a path by going right first, then left, then forward. It was not reducible.