Day Eight: Part Two

This commit is contained in:
Lewis Dale 2023-12-08 10:04:45 +00:00
parent c86bcbffb6
commit f81359618d

View File

@ -1,7 +1,6 @@
import {anyCharOf, int, newline, uniDecimal, uniLetter, whitespace} from "parjs";
import {anyCharOf, newline, uniDecimal, uniLetter, whitespace} from "parjs";
import {between, exactly, manySepBy, manyTill, or, stringify, then} from "parjs/combinators";
import fs from "fs";
import { Set } from 'immutable';
const patternParser = anyCharOf("LR").pipe(manyTill(newline().pipe(exactly(2))));
@ -90,14 +89,10 @@ export class DesertMap {
return step;
}
private isComplete(keys: string[]) {
return keys.every(key => key.endsWith('Z'));
}
public ghostStepsToZ(): number {
let keys = Object.keys(this.map).filter(key => key.endsWith('A'));
return keys.map(key => this.stepsToZ(key)).reduce(lcm, 1);
return keys.map(key => this.stepsToZ(key)).reduce(lcm);
}
}