Skip to content

Commit

Permalink
wip: d16
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktoriavh committed Dec 16, 2024
1 parent 8c4631b commit ef35e2a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
Empty file added inputs/16.txt
Empty file.
51 changes: 51 additions & 0 deletions src/16.ts
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;
34 changes: 34 additions & 0 deletions test/16.test.ts
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);
});
});

0 comments on commit ef35e2a

Please sign in to comment.