expeditaet
Version:
Advent of Code Solutions
23 lines (17 loc) • 595 B
text/typescript
import { descending, task } from '@alexaegis/advent-of-code-lib';
import packageJson from '../package.json';
import { parse } from './parse.js';
export const p1 = (input: string): number => {
const graph = parse(input);
const animalStart = graph.findNode((node) => node.value === 'S');
if (!animalStart) {
throw new Error('no starting position for the animal!');
}
const distanceMap = graph.flood({ start: animalStart });
return distanceMap
.entryArray()
.map(([_node, distance]) => distance)
.sort(descending)
.first();
};
await task(p1, packageJson.aoc); // 6733 ~68.44ms