advent of code 2023 day 16: stupid mirror mistake & forgot return

This commit is contained in:
Wouter Groeneveld 2023-12-16 20:29:57 +01:00
parent 56bd065fe6
commit 615772df82
1 changed files with 4 additions and 3 deletions

View File

@ -15,8 +15,8 @@ const mirrors = {
"\\": {
"U": "L",
"D": "R",
"R": "U",
"L": "D"
"R": "D",
"L": "U"
}
}
@ -31,16 +31,17 @@ const solve = (input) => {
return
const curr = tiles[pos[0]][pos[1]]
console.log(`trav ${pos} curr ${curr} direction ${direction}`)
energized.push([pos[0], pos[1], direction])
if(curr === '/' || curr === '\\') {
direction = mirrors[curr][direction]
} else if(curr === '|' && (direction === "L" || direction === "R")) {
traverse([pos[0] + directions["U"][0], pos[1] + directions["U"][1]], "U")
traverse([pos[0] + directions["D"][0], pos[1] + directions["D"][1]], "D")
return
} else if(curr === '-' && (direction === "U" || direction === "D")) {
traverse([pos[0] + directions["L"][0], pos[1] + directions["L"][1]], "L")
traverse([pos[0] + directions["R"][0], pos[1] + directions["R"][1]], "R")
return
}
traverse([pos[0] + directions[direction][0], pos[1] + directions[direction][1]], direction)
}