@altnovatrail/widgets 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cores/vector.schema.json +82 -3
- package/kinds/cells/cells.handles.json +145 -0
- package/kinds/cells/cells.schema.json +652 -4
- package/kinds/cells/vectors/bishop-grid-56-d1-1.json +105 -4
- package/kinds/cells/vectors/counter-cases.json +123 -0
- package/kinds/cells/vectors/counter-div-56-d1-3.json +57 -0
- package/kinds/cells/vectors/counter-div-56-d2-1.json +773 -0
- package/kinds/cells/vectors/counter-div-56-d2-3.json +65 -0
- package/kinds/cells/vectors/counter-div-56-d4-1.json +57 -0
- package/kinds/cells/vectors/counter-div-56-d4-2.json +106 -0
- package/kinds/cells/vectors/cut-cases.json +163 -0
- package/kinds/cells/vectors/cut-gaps-56-d2-1.json +142 -0
- package/kinds/cells/vectors/cut-grid-56-d2-4.json +45 -0
- package/kinds/cells/vectors/cut-grid-56-d4-1.json +154 -0
- package/kinds/cells/vectors/cut-grid-56-d4-2.json +136 -0
- package/kinds/cells/vectors/cut-invalid.json +48 -0
- package/kinds/cells/vectors/domino-grid-56-d3-2.json +238 -0
- package/kinds/cells/vectors/domino-limit.json +60 -0
- package/kinds/cells/vectors/domino-par-56-d3-2.json +194 -0
- package/kinds/cells/vectors/domino-par-56-d4-3.json +127 -0
- package/kinds/cells/vectors/figure-apart.json +47 -0
- package/kinds/cells/vectors/fold-12x12.json +79 -0
- package/kinds/cells/vectors/fold-14x14.json +79 -0
- package/kinds/cells/vectors/fold-26x26.json +79 -0
- package/kinds/cells/vectors/garden-enum-56-d3-4.json +96 -6
- package/kinds/cells/vectors/goat-grid-56-d4-4.json +325 -5
- package/kinds/cells/vectors/mosaic-grid-56-d2-2.json +84 -0
- package/kinds/cells/vectors/nodes-gaps-56-d2-2.json +44 -0
- package/kinds/cells/vectors/nodes-gaps-56-d4-2.json +70 -0
- package/kinds/cells/vectors/number-div-56-d2-2.json +49 -0
- package/kinds/cells/vectors/numbers-div-56-d3-1.json +24 -0
- package/kinds/cells/vectors/numbers-invalid.json +56 -0
- package/kinds/cells/vectors/paper-26x26.json +743 -0
- package/kinds/cells/vectors/paper-cube-12-d2-1.json +43 -19
- package/kinds/cells/vectors/paper-cube-12-d5-1.json +47 -4
- package/kinds/cells/vectors/paper-cube-56-d4-1.json +56 -5
- package/kinds/cells/vectors/paper-drawn-lines.json +149 -0
- package/kinds/cells/vectors/paper-grid-56-d1-2.json +46 -5
- package/kinds/cells/vectors/paper-turn-invalid.json +4 -4
- package/kinds/cells/vectors/path-6x6.json +119 -0
- package/kinds/cells/vectors/path-beside.json +108 -0
- package/kinds/cells/vectors/path-enum-12-d3-5.json +187 -0
- package/kinds/cells/vectors/path-enum-34-d4-3.json +412 -0
- package/kinds/cells/vectors/path-enum-56-d3-3.json +411 -0
- package/kinds/cells/vectors/path-enum-56-d3-5.json +351 -0
- package/kinds/cells/vectors/path-invalid.json +37 -0
- package/kinds/cells/vectors/path-limit.json +58 -0
- package/kinds/cells/vectors/path-maze.json +297 -0
- package/kinds/cells/vectors/path-unreachable.json +76 -0
- package/kinds/cells/vectors/perimeter-grid-56-d2-1.json +86 -0
- package/kinds/cells/vectors/perimeter-grid-56-d3-1.json +102 -0
- package/kinds/cells/vectors/perimeter-grid-56-d3-3.json +112 -0
- package/kinds/cells/vectors/perimeter-grid-56-d4-3.json +289 -0
- package/kinds/cells/vectors/polyomino-cases.json +191 -0
- package/kinds/cells/vectors/polyomino-grid-56-d3-4.json +205 -0
- package/kinds/cells/vectors/polyomino-grid-56-d4-1.json +137 -0
- package/kinds/cells/vectors/polyomino-grid-56-d5-3.json +157 -0
- package/kinds/cells/vectors/polyomino-invalid.json +45 -0
- package/kinds/cells/vectors/route-par-56-d3-3.json +245 -0
- package/kinds/cells/vectors/sides-gaps-56-d3-2.json +44 -0
- package/kinds/cells/vectors/sieve-div-56-d3-2.json +140 -0
- package/kinds/cells/vectors/tear-gaps-56-d3-1.json +84 -0
- package/kinds/cells/vectors/tear-limit.json +56 -0
- package/lib/cores/enumerate.d.ts +33 -0
- package/lib/cores/enumerate.js +77 -0
- package/lib/cores/kind.d.ts +55 -5
- package/lib/cores/search.d.ts +27 -8
- package/lib/cores/search.js +85 -28
- package/lib/kinds/cells/bishop.d.ts +1 -1
- package/lib/kinds/cells/bishop.js +1 -1
- package/lib/kinds/cells/counter.d.ts +26 -0
- package/lib/kinds/cells/counter.js +249 -0
- package/lib/kinds/cells/cut.d.ts +46 -0
- package/lib/kinds/cells/cut.js +400 -0
- package/lib/kinds/cells/figure.d.ts +13 -0
- package/lib/kinds/cells/figure.js +114 -0
- package/lib/kinds/cells/holes.d.ts +6 -0
- package/lib/kinds/cells/holes.js +57 -0
- package/lib/kinds/cells/kind.js +4 -2
- package/lib/kinds/cells/number.d.ts +6 -0
- package/lib/kinds/cells/number.js +32 -0
- package/lib/kinds/cells/operation.d.ts +12 -6
- package/lib/kinds/cells/paper.d.ts +10 -2
- package/lib/kinds/cells/paper.js +90 -8
- package/lib/kinds/cells/path.d.ts +38 -0
- package/lib/kinds/cells/path.js +288 -0
- package/lib/kinds/cells/piece.d.ts +10 -1
- package/lib/kinds/cells/piece.js +87 -3
- package/lib/kinds/cells/polyomino.d.ts +45 -0
- package/lib/kinds/cells/polyomino.js +450 -0
- package/lib/kinds/cells/registry.js +35 -4
- package/lib/kinds/cells/schema.js +41 -3
- package/lib/kinds/cells/sheet.d.ts +20 -1
- package/lib/kinds/cells/sheet.js +84 -6
- package/lib/kinds/cells/side.d.ts +33 -0
- package/lib/kinds/cells/side.js +86 -0
- package/lib/kinds/cells/sieve.d.ts +26 -0
- package/lib/kinds/cells/sieve.js +208 -0
- package/lib/kinds/cells/step.d.ts +1 -1
- package/lib/kinds/cells/step.js +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "The course's task div-56-d3-2: lemons counted out in twos, threes, fours, fives or sixes leave one over, and there is more than one lemon. A table of numbers from 1 to 100 in rows of 10, the sieve counting out by 2, 3, 4, 5 and 6 with 1 left. The goal asks the least number above 1 left, at its greatest, 61, the task's key: once by 3, by 4 and by 5, every number left is one more than a multiple of 60, and counting out by 2 or 6 then crosses out nothing more. A width counted twice, and one not given, are refused.",
|
|
3
|
+
"scene": {
|
|
4
|
+
"sheet": {
|
|
5
|
+
"rows": 10,
|
|
6
|
+
"cols": 10,
|
|
7
|
+
"numbers": {
|
|
8
|
+
"first": 1
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"operations": {
|
|
12
|
+
"sieve": {
|
|
13
|
+
"by": [2, 3, 4, 5, 6],
|
|
14
|
+
"left": 1
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"goal": {
|
|
18
|
+
"sieve_least": {
|
|
19
|
+
"above": 1
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"seed": "0",
|
|
24
|
+
"start": {
|
|
25
|
+
"state": {
|
|
26
|
+
"marks": {},
|
|
27
|
+
"sieve": []
|
|
28
|
+
},
|
|
29
|
+
"goal": true
|
|
30
|
+
},
|
|
31
|
+
"sequences": [
|
|
32
|
+
[
|
|
33
|
+
{
|
|
34
|
+
"move": {
|
|
35
|
+
"sieve": {
|
|
36
|
+
"by": 2
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"state": {
|
|
40
|
+
"marks": {},
|
|
41
|
+
"sieve": [2]
|
|
42
|
+
},
|
|
43
|
+
"goal": true
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"move": {
|
|
47
|
+
"sieve": {
|
|
48
|
+
"by": 2
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"refused": "counted"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"move": {
|
|
55
|
+
"sieve": {
|
|
56
|
+
"by": 7
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"refused": "no-width"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"move": {
|
|
63
|
+
"sieve": {
|
|
64
|
+
"by": 3
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"state": {
|
|
68
|
+
"marks": {},
|
|
69
|
+
"sieve": [2, 3]
|
|
70
|
+
},
|
|
71
|
+
"goal": true
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"move": {
|
|
75
|
+
"sieve": {
|
|
76
|
+
"by": 4
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"state": {
|
|
80
|
+
"marks": {},
|
|
81
|
+
"sieve": [2, 3, 4]
|
|
82
|
+
},
|
|
83
|
+
"goal": true
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"move": {
|
|
87
|
+
"sieve": {
|
|
88
|
+
"by": 5
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"state": {
|
|
92
|
+
"marks": {},
|
|
93
|
+
"sieve": [2, 3, 4, 5]
|
|
94
|
+
},
|
|
95
|
+
"goal": true
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"move": {
|
|
99
|
+
"sieve": {
|
|
100
|
+
"by": 6
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"state": {
|
|
104
|
+
"marks": {},
|
|
105
|
+
"sieve": [2, 3, 4, 5, 6]
|
|
106
|
+
},
|
|
107
|
+
"goal": true
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
],
|
|
111
|
+
"proof": {
|
|
112
|
+
"key": 61,
|
|
113
|
+
"asks": "max",
|
|
114
|
+
"witness": {
|
|
115
|
+
"path": [
|
|
116
|
+
{
|
|
117
|
+
"sieve": {
|
|
118
|
+
"by": 3
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"sieve": {
|
|
123
|
+
"by": 4
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"sieve": {
|
|
128
|
+
"by": 5
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
"ends": [
|
|
134
|
+
{
|
|
135
|
+
"marks": {},
|
|
136
|
+
"sieve": [3, 4, 5]
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "The course's task gaps-56-d3-1 by its simpler case: a strip of 3 stamps torn into single stamps, each tear running along its line through the piece it splits. The goal is every cell a part of its own; the fewest tears, 2, one fewer than the stamps, as the task's 39 for 5 rows of 8, whose sheet passes the kind's limit. The sequence tears both lines; a tear along a line torn already is refused.",
|
|
3
|
+
"scene": {
|
|
4
|
+
"sheet": {
|
|
5
|
+
"rows": 1,
|
|
6
|
+
"cols": 3
|
|
7
|
+
},
|
|
8
|
+
"operations": {
|
|
9
|
+
"cut": {
|
|
10
|
+
"along": "part"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"goal": {
|
|
14
|
+
"cells_apart": {}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"seed": "0",
|
|
18
|
+
"start": {
|
|
19
|
+
"state": {
|
|
20
|
+
"marks": {},
|
|
21
|
+
"cut": []
|
|
22
|
+
},
|
|
23
|
+
"goal": false
|
|
24
|
+
},
|
|
25
|
+
"sequences": [
|
|
26
|
+
[
|
|
27
|
+
{
|
|
28
|
+
"move": {
|
|
29
|
+
"cut": {
|
|
30
|
+
"side": "v2:A"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"state": {
|
|
34
|
+
"marks": {},
|
|
35
|
+
"cut": ["v2:A"]
|
|
36
|
+
},
|
|
37
|
+
"goal": false
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"move": {
|
|
41
|
+
"cut": {
|
|
42
|
+
"side": "v2:A"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"refused": "cut"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"move": {
|
|
49
|
+
"cut": {
|
|
50
|
+
"side": "v1:A"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"state": {
|
|
54
|
+
"marks": {},
|
|
55
|
+
"cut": ["v1:A", "v2:A"]
|
|
56
|
+
},
|
|
57
|
+
"goal": true
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
],
|
|
61
|
+
"proof": {
|
|
62
|
+
"key": 2,
|
|
63
|
+
"witness": {
|
|
64
|
+
"path": [
|
|
65
|
+
{
|
|
66
|
+
"cut": {
|
|
67
|
+
"side": "v1:A"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"cut": {
|
|
72
|
+
"side": "v2:A"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"ends": [
|
|
78
|
+
{
|
|
79
|
+
"marks": {},
|
|
80
|
+
"cut": ["v1:A", "v2:A"]
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "The course's sheet of stamps of gaps-56-d3-1, 5 rows of 8, torn along its lines into single stamps: its states, every way the tears have split it, pass the kind's limit, so the scene does not decide; its tears are still played. The first tear splits the whole sheet down v4; the next, from the side h2:1, splits the left half alone.",
|
|
3
|
+
"scene": {
|
|
4
|
+
"sheet": {
|
|
5
|
+
"rows": 5,
|
|
6
|
+
"cols": 8
|
|
7
|
+
},
|
|
8
|
+
"operations": {
|
|
9
|
+
"cut": {
|
|
10
|
+
"along": "part"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"goal": {
|
|
14
|
+
"cells_apart": {}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"seed": "0",
|
|
18
|
+
"start": {
|
|
19
|
+
"state": {
|
|
20
|
+
"marks": {},
|
|
21
|
+
"cut": []
|
|
22
|
+
},
|
|
23
|
+
"goal": false
|
|
24
|
+
},
|
|
25
|
+
"sequences": [
|
|
26
|
+
[
|
|
27
|
+
{
|
|
28
|
+
"move": {
|
|
29
|
+
"cut": {
|
|
30
|
+
"side": "v4:C"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"state": {
|
|
34
|
+
"marks": {},
|
|
35
|
+
"cut": ["v4:A", "v4:B", "v4:C", "v4:D", "v4:E"]
|
|
36
|
+
},
|
|
37
|
+
"goal": false
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"move": {
|
|
41
|
+
"cut": {
|
|
42
|
+
"side": "h2:1"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"state": {
|
|
46
|
+
"marks": {},
|
|
47
|
+
"cut": ["v4:A", "v4:B", "v4:C", "v4:D", "v4:E", "h2:1", "h2:2", "h2:3", "h2:4"]
|
|
48
|
+
},
|
|
49
|
+
"goal": false
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
],
|
|
53
|
+
"proof": {
|
|
54
|
+
"undecided": "limit"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Json } from "./kind.js";
|
|
2
|
+
import type { StateGraph, StateNode } from "./search.js";
|
|
3
|
+
/**
|
|
4
|
+
* The states of the graph that meet the goal, in the graph's order; where images is given, the
|
|
5
|
+
* first of each class alone, a state being one with every state images makes of it. images gives a
|
|
6
|
+
* state's whole orbit under the scene's symmetries, so that the first of a class stands for it
|
|
7
|
+
* whichever of its states the graph finds first.
|
|
8
|
+
*/
|
|
9
|
+
export declare function counted<State extends Json, Move>(graph: StateGraph<State, Move>, images?: (state: State) => readonly State[]): StateNode<State, Move>[];
|
|
10
|
+
/**
|
|
11
|
+
* How many ways of the fewest moves lead from the scene to a state that meets the goal, and the
|
|
12
|
+
* nearest such states, in the graph's order; undefined where no state meets it. A way is a sequence
|
|
13
|
+
* of moves, so two moves from one state to another are two ways; a move that leads to a state of
|
|
14
|
+
* its own layer or an earlier one starts no way of the fewest moves. The count is a sum that may
|
|
15
|
+
* pass the safe integers, which the caller checks: it then is no longer exact.
|
|
16
|
+
*/
|
|
17
|
+
export declare function ways<State, Move>(graph: StateGraph<State, Move>): {
|
|
18
|
+
readonly count: number;
|
|
19
|
+
readonly ends: readonly StateNode<State, Move>[];
|
|
20
|
+
} | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The greatest or least measure of a state that meets the goal, and the index of every state of
|
|
23
|
+
* that measure, in the order given; undefined where no state meets it. Throws a RangeError where a
|
|
24
|
+
* measure is no safe integer: a kind's rules are exact, so a fraction is a fault of the kind.
|
|
25
|
+
*/
|
|
26
|
+
export declare function extreme<State>(nodes: readonly {
|
|
27
|
+
readonly index: number;
|
|
28
|
+
readonly goal: boolean;
|
|
29
|
+
readonly state: State;
|
|
30
|
+
}[], which: "max" | "min", measure: (state: State) => number): {
|
|
31
|
+
readonly value: number;
|
|
32
|
+
readonly at: readonly number[];
|
|
33
|
+
} | undefined;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The core of enumeration: what a key that is a count, a maximum or a minimum reads off a scene's
|
|
2
|
+
// whole state graph, which the search core builds within the kind's limit. It adds no state to the
|
|
3
|
+
// graph and walks it no deeper, so the kind's one limit bounds it as it bounds the search.
|
|
4
|
+
import { canonicalKey } from "./key.js";
|
|
5
|
+
/**
|
|
6
|
+
* The states of the graph that meet the goal, in the graph's order; where images is given, the
|
|
7
|
+
* first of each class alone, a state being one with every state images makes of it. images gives a
|
|
8
|
+
* state's whole orbit under the scene's symmetries, so that the first of a class stands for it
|
|
9
|
+
* whichever of its states the graph finds first.
|
|
10
|
+
*/
|
|
11
|
+
export function counted(graph, images) {
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
const found = [];
|
|
14
|
+
for (const node of graph.nodes) {
|
|
15
|
+
if (!node.goal || seen.has(node.key)) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
found.push(node);
|
|
19
|
+
for (const image of images?.(node.state) ?? []) {
|
|
20
|
+
seen.add(canonicalKey(image));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return found;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* How many ways of the fewest moves lead from the scene to a state that meets the goal, and the
|
|
27
|
+
* nearest such states, in the graph's order; undefined where no state meets it. A way is a sequence
|
|
28
|
+
* of moves, so two moves from one state to another are two ways; a move that leads to a state of
|
|
29
|
+
* its own layer or an earlier one starts no way of the fewest moves. The count is a sum that may
|
|
30
|
+
* pass the safe integers, which the caller checks: it then is no longer exact.
|
|
31
|
+
*/
|
|
32
|
+
export function ways(graph) {
|
|
33
|
+
const nearest = graph.nodes.find((node) => node.goal);
|
|
34
|
+
if (nearest === undefined) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
// The graph lists its states by layers, so every way into a state is summed before it is read.
|
|
38
|
+
const count = graph.nodes.map((node) => (node.layer === 0 ? 1 : 0));
|
|
39
|
+
for (const node of graph.nodes) {
|
|
40
|
+
for (const edge of node.next) {
|
|
41
|
+
if (graph.nodes[edge.to].layer === node.layer + 1) {
|
|
42
|
+
count[edge.to] = count[edge.to] + count[node.index];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const ends = graph.nodes.filter((node) => node.goal && node.layer === nearest.layer);
|
|
47
|
+
return {
|
|
48
|
+
count: ends.reduce((sum, node) => sum + count[node.index], 0),
|
|
49
|
+
ends,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The greatest or least measure of a state that meets the goal, and the index of every state of
|
|
54
|
+
* that measure, in the order given; undefined where no state meets it. Throws a RangeError where a
|
|
55
|
+
* measure is no safe integer: a kind's rules are exact, so a fraction is a fault of the kind.
|
|
56
|
+
*/
|
|
57
|
+
export function extreme(nodes, which, measure) {
|
|
58
|
+
let value;
|
|
59
|
+
let at = [];
|
|
60
|
+
for (const node of nodes) {
|
|
61
|
+
if (!node.goal) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const measured = measure(node.state);
|
|
65
|
+
if (!Number.isSafeInteger(measured)) {
|
|
66
|
+
throw new RangeError(`a measure is a safe integer: ${String(measured)}`);
|
|
67
|
+
}
|
|
68
|
+
if (value === undefined || (which === "max" ? measured > value : measured < value)) {
|
|
69
|
+
value = measured;
|
|
70
|
+
at = [node.index];
|
|
71
|
+
}
|
|
72
|
+
else if (measured === value) {
|
|
73
|
+
at.push(node.index);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return value === undefined ? undefined : { value, at };
|
|
77
|
+
}
|
package/lib/cores/kind.d.ts
CHANGED
|
@@ -49,8 +49,40 @@ export interface Kind<Scene, State extends Json, Move extends Json> {
|
|
|
49
49
|
hasGoal(scene: Scene): boolean;
|
|
50
50
|
/** Whether the state meets the scene's goal; never true for a scene with no goal. */
|
|
51
51
|
meets(scene: Scene, state: State): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* What the scene's goal asks of its state graph, the key its proof gives; a kind that leaves it
|
|
54
|
+
* out asks the fewest moves, and a scene with no goal asks nothing.
|
|
55
|
+
*/
|
|
56
|
+
asks?(scene: Scene): Ask<State>;
|
|
52
57
|
}
|
|
53
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* The key a scene's goal asks, over every state the scene reaches:
|
|
60
|
+
* - fewest — the fewest moves to a state that meets the goal;
|
|
61
|
+
* - count — how many states meet it, two of them one where images makes one of the other; images
|
|
62
|
+
* gives every state the scene's symmetries make of a state, its whole orbit, so that being one
|
|
63
|
+
* holds both ways;
|
|
64
|
+
* - paths — how many ways of the fewest moves lead to a state that meets it, two moves to one state
|
|
65
|
+
* two ways; where every move leads one layer on, as moves right and down do, that is every way;
|
|
66
|
+
* - max, min — the greatest or least measure of a state that meets it, a safe integer, since the
|
|
67
|
+
* rules are exact.
|
|
68
|
+
* Where no state meets the goal, the key is "unreachable", whatever the goal asks.
|
|
69
|
+
*/
|
|
70
|
+
export type Ask<State> = {
|
|
71
|
+
readonly key: "fewest";
|
|
72
|
+
} | {
|
|
73
|
+
readonly key: "count";
|
|
74
|
+
images?(state: State): readonly State[];
|
|
75
|
+
} | {
|
|
76
|
+
readonly key: "paths";
|
|
77
|
+
} | {
|
|
78
|
+
readonly key: "max" | "min";
|
|
79
|
+
measure(state: State): number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Why a scene gives no proof: limit, its state graph passes the kind's limit, or a count of ways
|
|
83
|
+
* passes the safe integers, beyond what the solver takes either way; invalid, the kind refuses it;
|
|
84
|
+
* no-goal, it has no goal to prove.
|
|
85
|
+
*/
|
|
54
86
|
export type Undecided = {
|
|
55
87
|
readonly undecided: "limit";
|
|
56
88
|
} | {
|
|
@@ -60,10 +92,14 @@ export type Undecided = {
|
|
|
60
92
|
readonly undecided: "no-goal";
|
|
61
93
|
};
|
|
62
94
|
/**
|
|
63
|
-
* A proof as JSON, as the scene vectors and a module's build take it. The key is
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
95
|
+
* A proof as JSON, as the scene vectors and a module's build take it. The key is a whole number,
|
|
96
|
+
* or "unreachable", whose witness is the whole state graph, given by the count of states in each
|
|
97
|
+
* of its layers. A number with no member asks is the fewest moves to the goal, a path of them its
|
|
98
|
+
* witness; asks names any other key and its witness: count, a path to each state counted — one of
|
|
99
|
+
* each class where the scene gives symmetries — in the graph's order; paths, the first of the
|
|
100
|
+
* ways counted; max or min, the path to the first state of that measure. The ends are the states
|
|
101
|
+
* the witness ends in, each meeting the goal. The member witness names its form, so that a core
|
|
102
|
+
* whose witness is no path adds its own.
|
|
67
103
|
*/
|
|
68
104
|
export type ProofJson = {
|
|
69
105
|
readonly key: number;
|
|
@@ -71,6 +107,20 @@ export type ProofJson = {
|
|
|
71
107
|
readonly path: readonly Json[];
|
|
72
108
|
};
|
|
73
109
|
readonly ends: readonly Json[];
|
|
110
|
+
} | {
|
|
111
|
+
readonly key: number;
|
|
112
|
+
readonly asks: "count";
|
|
113
|
+
readonly witness: {
|
|
114
|
+
readonly paths: readonly (readonly Json[])[];
|
|
115
|
+
};
|
|
116
|
+
readonly ends: readonly Json[];
|
|
117
|
+
} | {
|
|
118
|
+
readonly key: number;
|
|
119
|
+
readonly asks: "paths" | "max" | "min";
|
|
120
|
+
readonly witness: {
|
|
121
|
+
readonly path: readonly Json[];
|
|
122
|
+
};
|
|
123
|
+
readonly ends: readonly Json[];
|
|
74
124
|
} | {
|
|
75
125
|
readonly key: "unreachable";
|
|
76
126
|
readonly witness: {
|
package/lib/cores/search.d.ts
CHANGED
|
@@ -12,7 +12,10 @@ export interface StateNode<State, Move> {
|
|
|
12
12
|
/** The fewest moves from the scene to the state. */
|
|
13
13
|
readonly layer: number;
|
|
14
14
|
readonly goal: boolean;
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The fewest moves from the state to a state the key aims at — one that meets the goal, and where
|
|
17
|
+
* the goal asks a maximum or a minimum, one of that measure —; null where none can be reached.
|
|
18
|
+
*/
|
|
16
19
|
readonly distance: number | null;
|
|
17
20
|
/** Every move the rules take from the state, in the kind's order, a move that changes nothing among them. */
|
|
18
21
|
readonly next: readonly Edge<Move>[];
|
|
@@ -40,11 +43,22 @@ export type GraphResult<State, Move> = {
|
|
|
40
43
|
readonly undecided: "invalid";
|
|
41
44
|
readonly errors: readonly SceneError[];
|
|
42
45
|
}));
|
|
46
|
+
/**
|
|
47
|
+
* A scene's proof with its whole state graph: the key the goal asks with its witness — the path to
|
|
48
|
+
* the state it ends in, or for a count a path to each state counted — and those states.
|
|
49
|
+
*/
|
|
43
50
|
export type Proof<State, Move> = {
|
|
44
51
|
readonly key: number;
|
|
52
|
+
readonly asks: "fewest" | "paths" | "max" | "min";
|
|
45
53
|
readonly path: readonly Move[];
|
|
46
54
|
readonly ends: readonly State[];
|
|
47
55
|
readonly graph: StateGraph<State, Move>;
|
|
56
|
+
} | {
|
|
57
|
+
readonly key: number;
|
|
58
|
+
readonly asks: "count";
|
|
59
|
+
readonly paths: readonly (readonly Move[])[];
|
|
60
|
+
readonly ends: readonly State[];
|
|
61
|
+
readonly graph: StateGraph<State, Move>;
|
|
48
62
|
} | {
|
|
49
63
|
readonly key: "unreachable";
|
|
50
64
|
readonly ends: readonly [];
|
|
@@ -54,16 +68,21 @@ export type Proof<State, Move> = {
|
|
|
54
68
|
* The whole state graph of a scene, read from its JSON by the kind's schema: every state the
|
|
55
69
|
* scene's moves reach, layer by layer, states that are equal by their canonical key merged. A
|
|
56
70
|
* graph with more states than the kind's limit is undecided, wherever its goal lies: the limit
|
|
57
|
-
* holds every state a learner can reach, not only the search from the scene to the goal.
|
|
71
|
+
* holds every state a learner can reach, not only the search from the scene to the goal. A
|
|
72
|
+
* measure the goal asks that is no safe integer throws, as a state that is no JSON of integers
|
|
73
|
+
* does: either is a fault of the kind, not of the scene.
|
|
58
74
|
*/
|
|
59
75
|
export declare function stateGraph<Scene, State extends Json, Move extends Json>(kind: Kind<Scene, State, Move>, input: unknown, seed: string): GraphResult<State, Move>;
|
|
60
76
|
/**
|
|
61
|
-
* The proof of a scene, read from its JSON by the kind's schema. For a scene with a goal
|
|
62
|
-
* the fewest moves to the goal, with the path of the first state in the graph's order that
|
|
63
|
-
* it;
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
77
|
+
* The proof of a scene, read from its JSON by the kind's schema. For a scene with a goal, the key
|
|
78
|
+
* it asks: the fewest moves to the goal, with the path of the first state in the graph's order that
|
|
79
|
+
* meets it; how many states meet it, with a path to each, the first of each class where the scene
|
|
80
|
+
* gives symmetries; how many ways of the fewest moves reach it, with the first; or the greatest or
|
|
81
|
+
* least measure of a state that meets it, with the path to the first state of it. Where no state of
|
|
82
|
+
* the graph meets the goal, the key is "unreachable", the whole graph its witness. The order of the
|
|
83
|
+
* graph follows the kind's order of moves, so the same scene gives the same proof on every run. A
|
|
84
|
+
* scene with no goal has nothing to prove once its graph is within the limit; past the limit it
|
|
85
|
+
* does not decide, as any scene, nor where a count of ways passes what a key holds exactly.
|
|
67
86
|
*/
|
|
68
87
|
export declare function prove<Scene, State extends Json, Move extends Json>(kind: Kind<Scene, State, Move>, input: unknown, seed: string): Proof<State, Move>;
|
|
69
88
|
/** A proof as JSON, as the scene vectors and a module's build take it. */
|