-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
252ecf0
commit 8a642bc
Showing
6 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Grid } from '../../utils'; | ||
|
||
const Type = { | ||
OPEN_SPACE: true, | ||
WALL: false, | ||
}; | ||
|
||
class Maze extends Grid { | ||
constructor(seed) { | ||
super(); | ||
this.seed = seed; | ||
} | ||
|
||
getPoint(x, y) { | ||
let point = super.getPoint(x, y); | ||
if (!point) { | ||
point = this.set(x, y); | ||
} | ||
return point; | ||
} | ||
|
||
set(x, y) { | ||
const point = super.set(x, y); | ||
|
||
const base = x * x + 3 * x + 2 * x * y + y + y * y; | ||
const sum = base + this.seed; | ||
const ones = sum.toString(2).split('').filter(char => char === '1'); | ||
const even = ones.length % 2 === 0; | ||
const value = even ? Type.OPEN_SPACE : Type.WALL; | ||
|
||
point.value = value; | ||
return point; | ||
} | ||
} | ||
|
||
export default Maze; | ||
export { Type }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env node --experimental-modules --no-warnings | ||
|
||
import { day } from '..'; | ||
import { astar } from '../../utils'; | ||
|
||
import Maze, { Type } from './Maze'; | ||
import examples from './input/examples'; | ||
import puzzleInput from './input'; | ||
|
||
const traverse = (start, goal) => ( | ||
astar(start, goal, { | ||
neighborsFor: point => point.adjacentNeighbors.filter(neighbor => ( | ||
neighbor.value === Type.OPEN_SPACE | ||
)), | ||
}) | ||
); | ||
|
||
day(13).part(1).test(examples).feed(puzzleInput).solution((input, isExample) => { | ||
const maze = new Maze(input); | ||
const start = maze.getPoint(1, 1); | ||
const goal = isExample ? maze.getPoint(7, 4) : maze.getPoint(31, 39); | ||
return traverse(start, goal).score; | ||
}); | ||
|
||
// day(13).part(2).test(examples).feed(null).solution((input) => { | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { example } from '../../../utils'; | ||
|
||
export default [ | ||
example(10, 11), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 1350; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters