import { Dusa } from "https://unpkg.com/dusa@0.0.11/lib/client.js";
const INPUT = `
...........
.....###.#.
.###.##..#.
..#.#...#..
....#.#....
.##..S####.
.##..#...#.
.......##..
.##.#.####.
.##..##.##.
...........
`
.trim()
.split("\n")
.map((line) => line.split(""));
const DISTANCE = 6;
const dusa = new Dusa(`
# AOC Day 21
#builtin NAT_SUCC s
# Input to start and node facts
start is (pair X Y) :-
field _ Y is Row,
field Row X is "S".
plot ".".
plot "S".
node (pair X Y) :-
field _ Y is Row,
field Row X is Ch,
plot Ch.
# Nodes to connected edges
edge (pair X Y) (pair X (s Y)) :-
node (pair X Y),
node (pair X (s Y)).
edge (pair X Y) (pair (s X) Y) :-
node (pair X Y),
node (pair (s X) Y).
edge A B :- edge B A.
# Locations reachable with N steps remaining
reachable D start :- distance is D.
reachable N B :- reachable (s N) A, edge A B.
`);
dusa.load(INPUT, "field");
dusa.assert({ name: "distance", args: [], value: DISTANCE });
console.log([...dusa.solution.lookup("reachable", 0)].length);