diff --git a/src/day_eight.test.ts b/src/day_eight.test.ts index 92346fa..fbd37fa 100644 --- a/src/day_eight.test.ts +++ b/src/day_eight.test.ts @@ -30,12 +30,12 @@ XXX = (XXX, XXX)` it('should calculate the number of steps needed to reach ZZZ', () => { const map = new DesertMap(input); - expect(map.stepsTo('ZZZ')).toEqual(2); + expect(map.stepsToZ('AAA')).toEqual(2); }); it('should repeat the pattern', () => { const map = new DesertMap(repeatedInput); - expect(map.stepsTo('ZZZ')).toEqual(6); + expect(map.stepsToZ('AAA')).toEqual(6); }); it('should count how many steps it takes to get from every node beginning with A, to every node ending in Z simultaneously', () => { diff --git a/src/day_eight.ts b/src/day_eight.ts index 6411094..d522c39 100644 --- a/src/day_eight.ts +++ b/src/day_eight.ts @@ -45,28 +45,6 @@ export class DesertMap { } } - public stepsTo(node: string): number { - let step = 0; - let curr = "AAA"; - - while (curr !== node) { - const instruction = this.pattern[step % this.pattern.length]; - - const [left, right] = this.map[curr]; - - if (instruction === "L" && left) { - curr = left; - } else if (instruction === "R" && right) { - curr = right; - } - - if (!curr) return 0; - - step++; - } - return step; - } - public stepsToZ(from: string): number { let step = 0; let curr = from; @@ -101,7 +79,7 @@ export const runDayEight = () => { const input = fs.readFileSync('./inputs/day_eight_input.txt', 'utf-8').trimEnd(); const map = new DesertMap(input); - console.log(map.stepsTo('ZZZ')); + console.log(map.stepsToZ('AAA')); console.log(map.ghostStepsToZ()); } \ No newline at end of file