From 517ad35923cd726d192902450a7e10f3e0f14fb4 Mon Sep 17 00:00:00 2001 From: Alix von Schirp Date: Thu, 12 Dec 2024 02:12:49 +0100 Subject: [PATCH] WIP-Day 6 Part1-testinput working, input not working --- Day 06/Part 1/index.ts | 93 ++++++++++++++++++++++++++++++++++++++++++ Day 06/Part 2/index.ts | 0 2 files changed, 93 insertions(+) create mode 100644 Day 06/Part 1/index.ts create mode 100644 Day 06/Part 2/index.ts diff --git a/Day 06/Part 1/index.ts b/Day 06/Part 1/index.ts new file mode 100644 index 0000000..27c1ea9 --- /dev/null +++ b/Day 06/Part 1/index.ts @@ -0,0 +1,93 @@ +import fs from 'node:fs'; + +type Vec2d = {y: number, x: number} + +let visited: Map = new Map() +let obstacles: boolean[][] = [] +let position: Vec2d = {x: -1, y: -1} + +let dir_NORTH: Vec2d = {x: 0, y: -1} +let dir_EAST: Vec2d = {x: 1, y: 0 } +let dir_SOUTH: Vec2d = {x: 0, y: 1} +let dir_WEST: Vec2d = {x: -1, y: 0} + +let direction: Vec2d = dir_NORTH + + +export default function runner(input: string) { + + + fs.readFile(`./${input}`, 'utf8', async (err, data) => { + if (err) throw err; + + + data.split("\n").forEach((value, index) => { + for (let i = 0; i < value.length; i++) { + if (obstacles[i] === undefined) obstacles[i] = [] + if (obstacles[i] === undefined) throw new Error(); + // @ts-ignore + obstacles[i][index] = value.charAt(i) === '#' + if (value.charAt(i) === '^') position = {x: i, y: index} + } + }) + + console.log(position) + console.log(position) + console.log(position) + console.log(position) + console.log(position) + + // @ts-ignore + while (position.x>0 && position.y>0 && position.x ${positionToString(position)}`) + // @ts-ignore + visited.set(JSON.stringify(position), true) + return true +} + +function rotate(): { x: number, y: number } { + switch (direction) { + case dir_NORTH: + console.log(`rotate ${positionToString(dir_NORTH)} => ${positionToString(dir_EAST)}`) + return dir_EAST + case dir_EAST: + console.log(`rotate ${positionToString(dir_EAST)} => ${positionToString(dir_SOUTH)}`) + return dir_SOUTH; + case dir_SOUTH: + console.log(`rotate ${positionToString(dir_SOUTH)} => ${positionToString(dir_WEST)}`) + return dir_WEST; + case dir_WEST: + console.log(`rotate ${positionToString(dir_WEST)} => ${positionToString(dir_NORTH)}`) + return dir_NORTH; + } + return dir_NORTH +} + +const positionToString = function (a: Vec2d){ + return `x: ${a.x} | y:${a.y}` +} \ No newline at end of file diff --git a/Day 06/Part 2/index.ts b/Day 06/Part 2/index.ts new file mode 100644 index 0000000..e69de29