From b4052d956f15f9de1c19967a2782cfbade15e164 Mon Sep 17 00:00:00 2001 From: Lewis Dale Date: Fri, 8 Dec 2023 10:08:22 +0000 Subject: [PATCH] Tidy up Day Eight a bit --- src/day_eight.test.ts | 4 ++-- src/day_eight.ts | 24 +----------------------- 2 files changed, 3 insertions(+), 25 deletions(-) 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