Public
Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
March 8, 2024