-
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
8c4631b
commit ef35e2a
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,51 @@ | ||
import { to2D } from "../utils/to2d"; | ||
|
||
function solution(input: string): { part1: string; part2: string } { | ||
let result1 = 0; | ||
let result2 = 0; | ||
|
||
const maze = to2D(input); | ||
const REINDEER = "S"; | ||
const EXIT = "E"; | ||
const WALL = "#"; | ||
const POINTS = { | ||
foward: 1, | ||
turn: 1000, | ||
}; | ||
|
||
const reindeerPosition: { x: number; y: number } = maze.reduce( | ||
(acc, row, y) => { | ||
const x = row.indexOf(REINDEER); | ||
if (x !== -1) { | ||
acc = { x, y }; | ||
} | ||
return acc; | ||
}, | ||
{ x: -1, y: -1 } | ||
); | ||
|
||
function heuristic(a: { x: number; y: number }, b: { x: number; y: number }) { | ||
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y); | ||
} | ||
|
||
function aStar( | ||
start: { x: number; y: number }, | ||
goal: { x: number; y: number } | ||
) { | ||
const directions = [ | ||
{ x: 0, y: 1 }, // down | ||
{ x: 1, y: 0 }, // right | ||
{ x: 0, y: -1 }, // up | ||
{ x: -1, y: 0 }, // left | ||
]; | ||
|
||
// calculate the cost of moving from the start to the end | ||
} | ||
|
||
return { | ||
part1: result1.toString(), | ||
part2: result2.toString(), | ||
}; | ||
} | ||
|
||
export default solution; |
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,34 @@ | ||
import { expect, test, describe } from "bun:test"; | ||
import solution from "../src/16"; | ||
|
||
const EXAMPLE_1 = `############### | ||
#.......#....E# | ||
#.#.###.#.###.# | ||
#.....#.#...#.# | ||
#.###.#####.#.# | ||
#.#.#.......#.# | ||
#.#.#####.###.# | ||
#...........#.# | ||
###.#.#####.#.# | ||
#...#.....#.#.# | ||
#.#.#.###.#.#.# | ||
#.....#...#.#.# | ||
#.###.#.#.#.#.# | ||
#S..#.....#...# | ||
###############`; | ||
const RESULT_1 = "7036"; | ||
|
||
const EXAMPLE_2 = EXAMPLE_1; | ||
const RESULT_2 = "31"; | ||
|
||
describe("Day 16", () => { | ||
test("Part 1", () => { | ||
const result = solution(EXAMPLE_1); | ||
expect(result.part1).toBe(RESULT_1); | ||
}); | ||
|
||
test("Part 2", () => { | ||
const result = solution(EXAMPLE_2); | ||
expect(result.part2).toBe(RESULT_2); | ||
}); | ||
}); |