i really don't know what's going wrong here
This commit is contained in:
parent
3f33f23c96
commit
a4d4dc2b23
1 changed files with 13 additions and 8 deletions
|
@ -9,7 +9,7 @@ type Direction = "up" | "right" | "down" | "left"
|
||||||
class DaySix implements Solvable {
|
class DaySix implements Solvable {
|
||||||
input: string[][] = readInput('06').split('\n').map(col => col.split(''))
|
input: string[][] = readInput('06').split('\n').map(col => col.split(''))
|
||||||
map = this.input
|
map = this.input
|
||||||
visitedLoc: Map<[number, number], null> = new Map()
|
visitedLoc: Map<string, null> = new Map()
|
||||||
|
|
||||||
// assigned in part1
|
// assigned in part1
|
||||||
startingPosition: [number, number] = [0, 0]
|
startingPosition: [number, number] = [0, 0]
|
||||||
|
@ -44,9 +44,9 @@ class DaySix implements Solvable {
|
||||||
walk = (x: number, y: number, direction: Direction): [boolean, number, number, Direction] => {
|
walk = (x: number, y: number, direction: Direction): [boolean, number, number, Direction] => {
|
||||||
const nextStepInBounds = {
|
const nextStepInBounds = {
|
||||||
up: y >= 1,
|
up: y >= 1,
|
||||||
down: y <= this.map.length,
|
down: y < this.map.length,
|
||||||
left: x >= 1,
|
left: x >= 1,
|
||||||
right: x <= this.map[0].length,
|
right: x < this.map[0].length,
|
||||||
}
|
}
|
||||||
|
|
||||||
// if oob, return true
|
// if oob, return true
|
||||||
|
@ -66,17 +66,19 @@ class DaySix implements Solvable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// path [y, x][]
|
// path [y, x][]
|
||||||
visualizePath = (path: [number, number][]): string => {
|
visualizePath = (path: string[]): string => {
|
||||||
const width = this.map[0].length
|
const width = this.map[0].length
|
||||||
const screenMat: string[][] = []
|
const screenMat: string[][] = []
|
||||||
for (let i = 0; i < width; i++) screenMat.push(this.map[i].slice())
|
for (let i = 0; i < width; i++) screenMat.push(this.map[i].slice())
|
||||||
for (const [y, x] of path) {
|
for (const loc of path) {
|
||||||
|
const [y, x]: number[] = loc.split(',').map(coord => Number.parseInt(coord))
|
||||||
screenMat[y][x] = 'X'
|
screenMat[y][x] = 'X'
|
||||||
}
|
}
|
||||||
const screen: string = screenMat.map((line: string[]) => line.join('')).join('\n')
|
const screen: string = screenMat.map((line: string[]) => line.join('')).join('\n')
|
||||||
return screen
|
return screen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async part1(): Promise<Solvable> {
|
public async part1(): Promise<Solvable> {
|
||||||
// find starting position
|
// find starting position
|
||||||
this.input.forEach((line, y) => line.forEach((char, x) => { if (char === '^') this.startingPosition = [y, x] }))
|
this.input.forEach((line, y) => line.forEach((char, x) => { if (char === '^') this.startingPosition = [y, x] }))
|
||||||
|
@ -87,13 +89,13 @@ class DaySix implements Solvable {
|
||||||
// let i = 0
|
// let i = 0
|
||||||
while (!outOfBounds) {
|
while (!outOfBounds) {
|
||||||
[outOfBounds, x, y, direction] = this.walk(x, y, direction)
|
[outOfBounds, x, y, direction] = this.walk(x, y, direction)
|
||||||
this.visitedLoc.set([y, x], null)
|
this.visitedLoc.set(y + ',' + x, null)
|
||||||
// console animation thingy
|
// console animation thingy
|
||||||
|
|
||||||
// if (i % 10 === 0) {
|
// if (i % 10 === 0) {
|
||||||
// const screen = this.visualizePath(this.visitedLoc.keys().toArray())
|
// const screen = this.visualizePath(this.visitedLoc.keys().toArray())
|
||||||
// console.log(screen)
|
// console.log(screen)
|
||||||
// await delay(100)
|
// await delay(200)
|
||||||
// }
|
// }
|
||||||
// i++
|
// i++
|
||||||
}
|
}
|
||||||
|
@ -101,7 +103,10 @@ class DaySix implements Solvable {
|
||||||
const path = this.visitedLoc.keys().toArray()
|
const path = this.visitedLoc.keys().toArray()
|
||||||
const result: number = path.length
|
const result: number = path.length
|
||||||
console.log(this.visualizePath(path))
|
console.log(this.visualizePath(path))
|
||||||
console.log(path)
|
|
||||||
|
const allDistinct = path.filter((loc: string) => path.indexOf(loc) !== path.lastIndexOf(loc)).length === 0
|
||||||
|
console.log(allDistinct ? 'path values distinct' : 'path values not distinct')
|
||||||
|
|
||||||
console.log(result)
|
console.log(result)
|
||||||
|
|
||||||
return new Promise(() => this)
|
return new Promise(() => this)
|
||||||
|
|
Loading…
Reference in a new issue