@altnovatrail/picture-kit 0.1.1 → 0.2.0
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/lib/index.d.ts +45 -1
- package/lib/index.js +34 -3
- package/lib/kinds/balance.js +2 -3
- package/lib/kinds/calendar.d.ts +5 -1
- package/lib/kinds/calendar.js +33 -11
- package/lib/kinds/chart.js +2 -4
- package/lib/kinds/clock.d.ts +5 -0
- package/lib/kinds/clock.js +45 -4
- package/lib/kinds/coins.js +3 -2
- package/lib/kinds/column.js +2 -3
- package/lib/kinds/commands.d.ts +8 -6
- package/lib/kinds/commands.js +57 -15
- package/lib/kinds/containers.js +2 -1
- package/lib/kinds/countfig.d.ts +2 -0
- package/lib/kinds/countfig.js +6 -1
- package/lib/kinds/cubes.d.ts +29 -5
- package/lib/kinds/cubes.js +82 -34
- package/lib/kinds/die.d.ts +8 -0
- package/lib/kinds/die.js +75 -14
- package/lib/kinds/domino.js +3 -3
- package/lib/kinds/dotgrid.d.ts +3 -0
- package/lib/kinds/dotgrid.js +6 -4
- package/lib/kinds/figure.js +5 -4
- package/lib/kinds/fold-parts.d.ts +0 -2
- package/lib/kinds/fold-parts.js +0 -4
- package/lib/kinds/fold.d.ts +20 -1
- package/lib/kinds/fold.js +15 -6
- package/lib/kinds/fraction.js +3 -2
- package/lib/kinds/gauges.js +2 -1
- package/lib/kinds/gears.d.ts +21 -2
- package/lib/kinds/gears.js +113 -62
- package/lib/kinds/grid.d.ts +5 -0
- package/lib/kinds/grid.js +30 -2
- package/lib/kinds/groups.d.ts +3 -1
- package/lib/kinds/groups.js +142 -28
- package/lib/kinds/lanes.js +3 -2
- package/lib/kinds/layers.d.ts +6 -0
- package/lib/kinds/layers.js +23 -4
- package/lib/kinds/line.d.ts +4 -0
- package/lib/kinds/line.js +117 -32
- package/lib/kinds/matchsticks.d.ts +4 -0
- package/lib/kinds/matchsticks.js +5 -3
- package/lib/kinds/net.js +4 -3
- package/lib/kinds/overlay.d.ts +23 -1
- package/lib/kinds/overlay.js +7 -3
- package/lib/kinds/pieces.js +3 -2
- package/lib/kinds/plane-parts.d.ts +0 -2
- package/lib/kinds/plane-parts.js +0 -6
- package/lib/kinds/plane.js +6 -6
- package/lib/kinds/ropes.js +1 -3
- package/lib/kinds/shapes.js +5 -7
- package/lib/kinds/solids.js +3 -2
- package/lib/kinds/tangram.js +2 -4
- package/lib/kinds/target.js +4 -6
- package/lib/kinds/tiles.js +5 -4
- package/lib/kinds/venn.js +3 -5
- package/lib/noto.js +1 -0
- package/lib/objects.js +2 -1
- package/lib/read.d.ts +2 -2
- package/lib/read.js +3 -3
- package/lib/solve/balance.d.ts +11 -0
- package/lib/solve/balance.js +116 -1
- package/lib/solve/calendar.d.ts +46 -0
- package/lib/solve/calendar.js +206 -0
- package/lib/solve/choice-scenes.d.ts +20 -0
- package/lib/solve/choice-scenes.js +51 -0
- package/lib/solve/clock.d.ts +54 -0
- package/lib/solve/clock.js +240 -0
- package/lib/solve/coins.d.ts +71 -0
- package/lib/solve/coins.js +222 -0
- package/lib/solve/commands.d.ts +36 -0
- package/lib/solve/commands.js +210 -0
- package/lib/solve/countfig.d.ts +41 -0
- package/lib/solve/countfig.js +199 -0
- package/lib/solve/cubes.d.ts +49 -0
- package/lib/solve/cubes.js +255 -0
- package/lib/solve/die.d.ts +39 -0
- package/lib/solve/die.js +93 -0
- package/lib/solve/domino.d.ts +57 -0
- package/lib/solve/domino.js +263 -0
- package/lib/solve/enumerate.d.ts +75 -0
- package/lib/solve/enumerate.js +323 -0
- package/lib/solve/figure.d.ts +26 -0
- package/lib/solve/figure.js +88 -0
- package/lib/solve/fold.d.ts +22 -0
- package/lib/solve/fold.js +68 -0
- package/lib/solve/gaps.d.ts +65 -0
- package/lib/solve/gaps.js +292 -0
- package/lib/solve/gears.d.ts +33 -0
- package/lib/solve/gears.js +130 -0
- package/lib/solve/grid.d.ts +35 -0
- package/lib/solve/grid.js +194 -0
- package/lib/solve/groups.d.ts +93 -0
- package/lib/solve/groups.js +346 -0
- package/lib/solve/index.d.ts +60 -0
- package/lib/solve/index.js +194 -0
- package/lib/solve/layers.d.ts +30 -0
- package/lib/solve/layers.js +72 -0
- package/lib/solve/magic.d.ts +32 -0
- package/lib/solve/magic.js +216 -0
- package/lib/solve/matchsticks.d.ts +37 -0
- package/lib/solve/matchsticks.js +214 -0
- package/lib/solve/order.d.ts +94 -0
- package/lib/solve/order.js +419 -0
- package/lib/solve/overlay.d.ts +22 -0
- package/lib/solve/overlay.js +56 -0
- package/lib/solve/parity.d.ts +22 -0
- package/lib/solve/parity.js +27 -0
- package/lib/solve/pattern.d.ts +62 -0
- package/lib/solve/pattern.js +533 -0
- package/lib/solve/pieces.d.ts +57 -0
- package/lib/solve/pieces.js +309 -0
- package/lib/solve/pigeonhole.d.ts +38 -0
- package/lib/solve/pigeonhole.js +95 -0
- package/lib/solve/proof.d.ts +115 -0
- package/lib/solve/proof.js +105 -0
- package/lib/solve/pyramid.d.ts +28 -0
- package/lib/solve/pyramid.js +161 -0
- package/lib/solve/question.d.ts +25 -0
- package/lib/solve/question.js +75 -0
- package/lib/solve/shapes.d.ts +30 -0
- package/lib/solve/shapes.js +182 -0
- package/lib/solve/target.d.ts +40 -0
- package/lib/solve/target.js +190 -0
- package/lib/style.d.ts +1 -1
- package/lib/style.js +1 -1
- package/lib/words.d.ts +15 -0
- package/lib/words.js +39 -0
- package/package.json +1 -1
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { int, isObj, list, oneOf, only, text } from "../read.js";
|
|
2
|
+
import { checkThing, sameThing, wordOf } from "../things.js";
|
|
3
|
+
import { choicesOf } from "./choice-scenes.js";
|
|
4
|
+
import { permutations } from "./order.js";
|
|
5
|
+
import { letters, noScene, solved, unsolved, } from "./proof.js";
|
|
6
|
+
import { askOf, flagOf, sceneless } from "./question.js";
|
|
7
|
+
const members = {
|
|
8
|
+
"how-many-pairs": [],
|
|
9
|
+
"how-many-routes": [],
|
|
10
|
+
"how-many-pairs-within": [],
|
|
11
|
+
"which-is-missing": [],
|
|
12
|
+
"how-many-orders": [],
|
|
13
|
+
};
|
|
14
|
+
/** The givens each question takes. */
|
|
15
|
+
const takes = {
|
|
16
|
+
"how-many-pairs": ["counts"],
|
|
17
|
+
"how-many-routes": ["from", "via", "to"],
|
|
18
|
+
"how-many-pairs-within": ["count", "eachWay"],
|
|
19
|
+
"which-is-missing": ["kinds"],
|
|
20
|
+
"how-many-orders": ["things", "rules"],
|
|
21
|
+
};
|
|
22
|
+
/** The scene each question reads: groups or a map, or none. */
|
|
23
|
+
const reading = {
|
|
24
|
+
"how-many-pairs": "groups",
|
|
25
|
+
"how-many-routes": "map",
|
|
26
|
+
"how-many-pairs-within": undefined,
|
|
27
|
+
"which-is-missing": "groups",
|
|
28
|
+
"how-many-orders": undefined,
|
|
29
|
+
};
|
|
30
|
+
const orderMost = 4;
|
|
31
|
+
const shelfRules = ["at", "not-at", "next-to", "not-next-to", "left-of", "right-of"];
|
|
32
|
+
const sameSet = (a, b) => a.length === b.length &&
|
|
33
|
+
a.every((t) => b.some((u) => sameThing(t, u))) &&
|
|
34
|
+
b.every((t) => a.some((u) => sameThing(t, u)));
|
|
35
|
+
/** waysOf lists every way that takes one thing of each kind. */
|
|
36
|
+
function waysOf(kinds) {
|
|
37
|
+
return kinds.reduce((ways, kind) => ways.flatMap((w) => kind.map((t) => [...w, t])), [[]]);
|
|
38
|
+
}
|
|
39
|
+
/** groupThings lists the things of a group, refusing a thing that stands in it twice. */
|
|
40
|
+
function groupThings(scene, i, problems, at = "") {
|
|
41
|
+
const out = [];
|
|
42
|
+
scene.groups[i].items.forEach((item, j) => {
|
|
43
|
+
const path = `${at}${at ? "." : ""}groups[${i}].items[${j}]`;
|
|
44
|
+
if (item.count !== 1)
|
|
45
|
+
problems.push(`${path}.count: each choice stands once; ${item.count} alike are one choice`);
|
|
46
|
+
if (out.some((t) => sameThing(t, item.thing)))
|
|
47
|
+
problems.push(`${path}: ${wordOf(item.thing)} stands in the group twice`);
|
|
48
|
+
out.push(item.thing);
|
|
49
|
+
});
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
function checkThings(value, path, problems, least) {
|
|
53
|
+
const out = [];
|
|
54
|
+
list(value, path, problems, least, 4).forEach((t, i) => {
|
|
55
|
+
const before = problems.length;
|
|
56
|
+
checkThing(t, `${path}[${i}]`, problems);
|
|
57
|
+
if (problems.length > before)
|
|
58
|
+
return;
|
|
59
|
+
if (out.some((o) => sameThing(o, t)))
|
|
60
|
+
problems.push(`${path}[${i}]: ${wordOf(t)} is named twice`);
|
|
61
|
+
else
|
|
62
|
+
out.push(t);
|
|
63
|
+
});
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/** wayOf is the way a picture option shows: the things of its one group, each once. */
|
|
67
|
+
function wayOf(choice) {
|
|
68
|
+
return choice.groups[0].items.map((item) => item.thing);
|
|
69
|
+
}
|
|
70
|
+
function checkMissing(g, scene, offered, problems) {
|
|
71
|
+
const before = problems.length;
|
|
72
|
+
const kinds = list(g.kinds, "givens.kinds", problems, 2, 3).map((k, i) => checkThings(k, `givens.kinds[${i}]`, problems, 2));
|
|
73
|
+
const all = kinds.flat();
|
|
74
|
+
all.forEach((t, i) => {
|
|
75
|
+
if (all.findIndex((o) => sameThing(o, t)) !== i)
|
|
76
|
+
problems.push(`givens.kinds: ${wordOf(t)} is in two kinds`);
|
|
77
|
+
});
|
|
78
|
+
choicesOf(offered, "which-is-missing", "groups", (o, path) => {
|
|
79
|
+
if (o.groups.length !== 1)
|
|
80
|
+
problems.push(`${path}: must be a scene of one group, a way`);
|
|
81
|
+
else
|
|
82
|
+
groupThings(o, 0, problems, path);
|
|
83
|
+
}, problems);
|
|
84
|
+
if (problems.length > before)
|
|
85
|
+
return;
|
|
86
|
+
const shown = [];
|
|
87
|
+
scene.groups.forEach((_, i) => {
|
|
88
|
+
const way = groupThings(scene, i, problems);
|
|
89
|
+
const fits = way.length === kinds.length &&
|
|
90
|
+
kinds.every((kind) => way.filter((t) => kind.some((k) => sameThing(k, t))).length === 1);
|
|
91
|
+
if (!fits)
|
|
92
|
+
problems.push(`groups[${i}]: is not a way, one thing of each kind`);
|
|
93
|
+
else if (shown.some((w) => sameSet(w, way)))
|
|
94
|
+
problems.push(`groups[${i}]: shows the same way as another group`);
|
|
95
|
+
shown.push(way);
|
|
96
|
+
});
|
|
97
|
+
if (waysOf(kinds).length > 12)
|
|
98
|
+
problems.push("givens.kinds: at most 12 ways for the solver");
|
|
99
|
+
}
|
|
100
|
+
function checkRules(g, problems) {
|
|
101
|
+
const before = problems.length;
|
|
102
|
+
const things = list(g.things, "givens.things", problems, 2, orderMost);
|
|
103
|
+
things.forEach((t, i) => {
|
|
104
|
+
text(t, `givens.things[${i}]`, problems, 20);
|
|
105
|
+
if (things.indexOf(t) !== i)
|
|
106
|
+
problems.push(`givens.things[${i}]: ${String(t)} is named twice`);
|
|
107
|
+
});
|
|
108
|
+
if (problems.length > before || g.rules === undefined)
|
|
109
|
+
return;
|
|
110
|
+
const named = (value, path) => {
|
|
111
|
+
if (typeof value !== "string" || !things.includes(value))
|
|
112
|
+
problems.push(`${path}: must be one of givens.things`);
|
|
113
|
+
};
|
|
114
|
+
list(g.rules, "givens.rules", problems, 1, 6).forEach((r, i) => {
|
|
115
|
+
const path = `givens.rules[${i}]`;
|
|
116
|
+
if (!isObj(r)) {
|
|
117
|
+
problems.push(`${path}: must be a rule, as {"who": "kite", "is": "not-at", "place": "left-end"}`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const b = problems.length;
|
|
121
|
+
const is = oneOf(r.is, shelfRules, `${path}.is`, problems);
|
|
122
|
+
if (problems.length > b)
|
|
123
|
+
return;
|
|
124
|
+
const place = is === "at" || is === "not-at";
|
|
125
|
+
only(r, ["who", "is", place ? "place" : "of"], path, problems, `a rule ${is}`);
|
|
126
|
+
named(r.who, `${path}.who`);
|
|
127
|
+
if (place) {
|
|
128
|
+
if (r.place !== "left-end" && r.place !== "right-end")
|
|
129
|
+
int(r.place, `${path}.place`, problems, 1, things.length);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
named(r.of, `${path}.of`);
|
|
133
|
+
if (r.of === r.who)
|
|
134
|
+
problems.push(`${path}.of: is the same as who`);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function placeOf(scene, id, path, problems) {
|
|
139
|
+
if (typeof id !== "string" || !scene.places.some((p) => p.id === id))
|
|
140
|
+
problems.push(`${path}: must be the id of a place of the map`);
|
|
141
|
+
}
|
|
142
|
+
function check(question, givens, scene, offered) {
|
|
143
|
+
const problems = [];
|
|
144
|
+
const read = askOf(question, members, problems);
|
|
145
|
+
if (!read)
|
|
146
|
+
return problems;
|
|
147
|
+
const { ask } = read;
|
|
148
|
+
if (givens !== undefined && !isObj(givens)) {
|
|
149
|
+
problems.push("givens: must be an object");
|
|
150
|
+
return problems;
|
|
151
|
+
}
|
|
152
|
+
const g = givens ?? {};
|
|
153
|
+
only(g, takes[ask], "givens", problems, `the givens of ${ask}`);
|
|
154
|
+
const wants = reading[ask];
|
|
155
|
+
if (scene && scene.kind !== wants)
|
|
156
|
+
problems.push(`scene.kind: ${ask} reads ${wants ? `a scene of ${wants}` : "no scene; the statement tells it all"}`);
|
|
157
|
+
if (problems.length > 0)
|
|
158
|
+
return problems;
|
|
159
|
+
switch (ask) {
|
|
160
|
+
case "how-many-pairs":
|
|
161
|
+
if (!scene) {
|
|
162
|
+
list(g.counts, "givens.counts", problems, 2, 2).forEach((c, i) => {
|
|
163
|
+
int(c, `givens.counts[${i}]`, problems, 1, 12);
|
|
164
|
+
});
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
if (g.counts !== undefined)
|
|
168
|
+
problems.push("givens.counts: the scene draws the groups");
|
|
169
|
+
if (scene.groups.length !== 2)
|
|
170
|
+
problems.push("groups: how-many-pairs reads two groups");
|
|
171
|
+
else
|
|
172
|
+
for (const i of [0, 1])
|
|
173
|
+
groupThings(scene, i, problems);
|
|
174
|
+
break;
|
|
175
|
+
case "how-many-routes": {
|
|
176
|
+
if (!scene) {
|
|
177
|
+
sceneless(ask, "a map", problems);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
const map = scene;
|
|
181
|
+
placeOf(map, g.from, "givens.from", problems);
|
|
182
|
+
placeOf(map, g.to, "givens.to", problems);
|
|
183
|
+
if (g.via !== undefined)
|
|
184
|
+
placeOf(map, g.via, "givens.via", problems);
|
|
185
|
+
if (g.from === g.to)
|
|
186
|
+
problems.push("givens.to: is the same place as givens.from");
|
|
187
|
+
if (g.via !== undefined && (g.via === g.from || g.via === g.to))
|
|
188
|
+
problems.push("givens.via: is the start or the end");
|
|
189
|
+
if (map.route !== undefined)
|
|
190
|
+
problems.push("route: a highlighted way draws one of the ways counted");
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case "how-many-pairs-within":
|
|
194
|
+
int(g.count, "givens.count", problems, 2, 12);
|
|
195
|
+
flagOf(g.eachWay, "givens.eachWay", problems);
|
|
196
|
+
break;
|
|
197
|
+
case "which-is-missing":
|
|
198
|
+
if (!scene)
|
|
199
|
+
sceneless(ask, "the ways shown, a scene of groups", problems);
|
|
200
|
+
else
|
|
201
|
+
checkMissing(g, scene, offered, problems);
|
|
202
|
+
break;
|
|
203
|
+
case "how-many-orders":
|
|
204
|
+
checkRules(g, problems);
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
return problems;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* routes counts the ways from one place to another along the roads, none
|
|
211
|
+
* through a place twice, that pass via if it is given. The map holds at
|
|
212
|
+
* most 12 places, so the search walks every such way.
|
|
213
|
+
*/
|
|
214
|
+
function routes(map, from, to, via) {
|
|
215
|
+
const next = (id) => map.roads.flatMap((r) => (r.from === id ? [r.to] : r.to === id && !r.arrow ? [r.from] : []));
|
|
216
|
+
const seen = new Set([from]);
|
|
217
|
+
const walk = (at, passed) => {
|
|
218
|
+
if (at === to)
|
|
219
|
+
return passed ? 1 : 0;
|
|
220
|
+
let ways = 0;
|
|
221
|
+
for (const id of next(at)) {
|
|
222
|
+
if (seen.has(id))
|
|
223
|
+
continue;
|
|
224
|
+
seen.add(id);
|
|
225
|
+
ways += walk(id, passed || id === via);
|
|
226
|
+
seen.delete(id);
|
|
227
|
+
}
|
|
228
|
+
return ways;
|
|
229
|
+
};
|
|
230
|
+
return walk(from, via === undefined);
|
|
231
|
+
}
|
|
232
|
+
function keepsRule(order, rule) {
|
|
233
|
+
const at = order.indexOf(rule.who);
|
|
234
|
+
if ("place" in rule) {
|
|
235
|
+
const place = rule.place === "left-end"
|
|
236
|
+
? 0
|
|
237
|
+
: rule.place === "right-end"
|
|
238
|
+
? order.length - 1
|
|
239
|
+
: rule.place - 1;
|
|
240
|
+
return rule.is === "at" ? at === place : at !== place;
|
|
241
|
+
}
|
|
242
|
+
const of = order.indexOf(rule.of);
|
|
243
|
+
if (rule.is === "next-to")
|
|
244
|
+
return Math.abs(at - of) === 1;
|
|
245
|
+
if (rule.is === "not-next-to")
|
|
246
|
+
return Math.abs(at - of) !== 1;
|
|
247
|
+
return rule.is === "left-of" ? at < of : at > of;
|
|
248
|
+
}
|
|
249
|
+
function itemReads(scene) {
|
|
250
|
+
return scene.groups.flatMap((g, i) => g.items.map((_, j) => `groups[${i}].items[${j}]`));
|
|
251
|
+
}
|
|
252
|
+
function solve(scene, question, givens, offered) {
|
|
253
|
+
const g = givens ?? {};
|
|
254
|
+
switch (question.ask) {
|
|
255
|
+
case "how-many-pairs": {
|
|
256
|
+
if (!scene)
|
|
257
|
+
return solved({ number: g.counts[0] * g.counts[1] }, []);
|
|
258
|
+
const groups = scene.groups;
|
|
259
|
+
return solved({ number: groups[0].items.length * groups[1].items.length }, itemReads(scene));
|
|
260
|
+
}
|
|
261
|
+
case "how-many-routes": {
|
|
262
|
+
const map = scene;
|
|
263
|
+
const reads = [
|
|
264
|
+
...map.places.map((_, i) => `places[${i}]`),
|
|
265
|
+
...map.roads.map((_, i) => `roads[${i}]`),
|
|
266
|
+
];
|
|
267
|
+
return solved({ number: routes(map, g.from, g.to, g.via) }, reads);
|
|
268
|
+
}
|
|
269
|
+
case "how-many-pairs-within": {
|
|
270
|
+
const n = g.count;
|
|
271
|
+
return solved({ number: g.eachWay ? n * (n - 1) : (n * (n - 1)) / 2 }, []);
|
|
272
|
+
}
|
|
273
|
+
case "which-is-missing": {
|
|
274
|
+
if (!scene)
|
|
275
|
+
return noScene;
|
|
276
|
+
const groups = scene;
|
|
277
|
+
const shown = groups.groups.map((gr) => gr.items.map((item) => item.thing));
|
|
278
|
+
const missing = waysOf(g.kinds).filter((w) => !shown.some((s) => sameSet(s, w)));
|
|
279
|
+
const reads = itemReads(groups);
|
|
280
|
+
const hits = (offered?.choices ?? []).flatMap((o, i) => missing.some((w) => sameSet(w, wayOf(o))) ? [{ letter: letters[i] }] : []);
|
|
281
|
+
if (missing.length === 1 && hits.length === 1)
|
|
282
|
+
return solved(hits[0], reads);
|
|
283
|
+
const ways = missing.map((w) => w.map((t) => wordOf(t)).join(" and "));
|
|
284
|
+
return unsolved(missing.length === 0
|
|
285
|
+
? "the groups show every way"
|
|
286
|
+
: `${ways.join("; ")} ${missing.length === 1 ? "is" : "are"} missing, and ${hits.length} of the options show${hits.length === 1 ? "s" : ""} ${missing.length === 1 ? "it" : "one"}`, reads, hits);
|
|
287
|
+
}
|
|
288
|
+
case "how-many-orders": {
|
|
289
|
+
let ways = 0;
|
|
290
|
+
for (const order of permutations(g.things))
|
|
291
|
+
if ((g.rules ?? []).every((r) => keepsRule(order, r)))
|
|
292
|
+
ways++;
|
|
293
|
+
return solved({ number: ways }, []);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The facts of a scene of groups are its items; of a map, its places, its
|
|
299
|
+
* roads and its highlighted way.
|
|
300
|
+
*/
|
|
301
|
+
function facts(scene) {
|
|
302
|
+
if (scene.kind === "groups")
|
|
303
|
+
return itemReads(scene);
|
|
304
|
+
return [
|
|
305
|
+
...scene.places.map((_, i) => `places[${i}]`),
|
|
306
|
+
...scene.roads.map((_, i) => `roads[${i}]`),
|
|
307
|
+
...(scene.route ? ["route"] : []),
|
|
308
|
+
];
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* enumerateSolver lists the ways to choose, to go and to order: the
|
|
312
|
+
* questions of EnumerateQuestion. Every way is listed, at most 12 of all
|
|
313
|
+
* that take one thing of each kind and every order of at most four things;
|
|
314
|
+
* a map holds at most 12 places, and every way through them is walked.
|
|
315
|
+
*/
|
|
316
|
+
export const enumerateSolver = {
|
|
317
|
+
name: "enumerate",
|
|
318
|
+
kinds: ["groups", "map"],
|
|
319
|
+
questions: Object.keys(members),
|
|
320
|
+
check,
|
|
321
|
+
facts,
|
|
322
|
+
solve,
|
|
323
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type FigureScene } from "../kinds/figure.ts";
|
|
2
|
+
import { type Solver } from "./proof.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The questions about a card and its change, each answered by the letter of
|
|
5
|
+
* the right one of the task's picture options, figure scenes with show
|
|
6
|
+
* "result", each the card after its own change, or the card unchanged.
|
|
7
|
+
*
|
|
8
|
+
* - `mirror-image`: which option is the card flipped as the scene's flip
|
|
9
|
+
* says, its colours switched too if a swap says so; the scene has a flip
|
|
10
|
+
* and no turn.
|
|
11
|
+
* - `turned`: which option is the card after the scene's turn, its colours
|
|
12
|
+
* switched too if a swap says so; the scene has a turn and no flip.
|
|
13
|
+
*
|
|
14
|
+
* Every part of the card moves together: its colours, its dots, its things,
|
|
15
|
+
* arrows and letters, each turned and mirrored as the card is. The
|
|
16
|
+
* statement's picture asks — show "ask" — and never draws the answer. The
|
|
17
|
+
* question is refused where the card looks the same after its change, and
|
|
18
|
+
* where two options look the same; a thing or a letter turned or mirrored is
|
|
19
|
+
* taken to look the same, for a picture or a letter may be its own mirror
|
|
20
|
+
* image, and children of 6 write letters both ways round. It takes no givens.
|
|
21
|
+
*/
|
|
22
|
+
export type FigureQuestion = {
|
|
23
|
+
ask: "mirror-image" | "turned";
|
|
24
|
+
};
|
|
25
|
+
/** figureSolver picks the card after its change: the questions of FigureQuestion. */
|
|
26
|
+
export declare const figureSolver: Solver<FigureScene, FigureQuestion, Record<string, never>>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { change } from "../kinds/figure.js";
|
|
2
|
+
import { alike, choicesOf, pick, shows } from "./choice-scenes.js";
|
|
3
|
+
import { noScene } from "./proof.js";
|
|
4
|
+
import { askOf, noGivens, sceneless } from "./question.js";
|
|
5
|
+
const members = { "mirror-image": [], turned: [] };
|
|
6
|
+
/**
|
|
7
|
+
* keyOf names what a card shows; loose, it leaves out how its things and
|
|
8
|
+
* letters are turned and mirrored.
|
|
9
|
+
*/
|
|
10
|
+
function keyOf(card, loose) {
|
|
11
|
+
const look = (m) => {
|
|
12
|
+
if ("dot" in m)
|
|
13
|
+
return { dot: m.dot };
|
|
14
|
+
if ("arrow" in m)
|
|
15
|
+
return { arrow: m.arrow, turn: (m.turn ?? 0) % 360 };
|
|
16
|
+
const what = "letter" in m ? { letter: m.letter, color: m.color ?? null } : { thing: m.thing };
|
|
17
|
+
return loose ? what : { ...what, turn: (m.turn ?? 0) % 360, mirror: m.mirror === true };
|
|
18
|
+
};
|
|
19
|
+
const marks = [...(card.marks ?? [])]
|
|
20
|
+
.sort((a, b) => a.at.localeCompare(b.at))
|
|
21
|
+
.map((m) => ({ at: m.at, ...look(m) }));
|
|
22
|
+
return JSON.stringify({
|
|
23
|
+
shape: card.shape,
|
|
24
|
+
cut: card.cut ?? "none",
|
|
25
|
+
colors: card.colors,
|
|
26
|
+
marks,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const shownBy = (option) => change(option.card, option);
|
|
30
|
+
function check(question, givens, scene, offered) {
|
|
31
|
+
const problems = [];
|
|
32
|
+
noGivens(givens, problems);
|
|
33
|
+
const read = askOf(question, members, problems);
|
|
34
|
+
if (!read)
|
|
35
|
+
return problems;
|
|
36
|
+
const { ask } = read;
|
|
37
|
+
const before = problems.length;
|
|
38
|
+
const choices = choicesOf(offered, ask, "figure", (o, path) => {
|
|
39
|
+
shows(o, path, "result", "result", problems);
|
|
40
|
+
}, problems);
|
|
41
|
+
if (problems.length === before)
|
|
42
|
+
alike(choices, (o) => keyOf(shownBy(o), true), problems);
|
|
43
|
+
if (!scene) {
|
|
44
|
+
sceneless(ask, "a scene of figure, the card", problems);
|
|
45
|
+
return problems;
|
|
46
|
+
}
|
|
47
|
+
const flips = (scene.flip ?? "none") !== "none";
|
|
48
|
+
const turns = (scene.turn ?? 0) !== 0;
|
|
49
|
+
if (ask === "mirror-image" && !flips)
|
|
50
|
+
problems.push("flip: mirror-image asks of a card flipped over; give the scene a flip");
|
|
51
|
+
if (ask === "mirror-image" && turns)
|
|
52
|
+
problems.push("turn: mirror-image asks of a mirror alone; a turn and a mirror at once is two");
|
|
53
|
+
if (ask === "turned" && !turns)
|
|
54
|
+
problems.push("turn: turned asks of a card turned; give the scene a turn");
|
|
55
|
+
if (ask === "turned" && flips)
|
|
56
|
+
problems.push("flip: turned asks of a turn alone; a turn and a mirror at once is two");
|
|
57
|
+
if ((scene.show ?? "result") !== "ask")
|
|
58
|
+
problems.push('show: the statement\'s picture asks, show "ask", and draws no answer');
|
|
59
|
+
if (keyOf(change(scene.card, scene), true) === keyOf(scene.card, true))
|
|
60
|
+
problems.push("card: looks the same after its change, so the card unchanged would be right as well");
|
|
61
|
+
return problems;
|
|
62
|
+
}
|
|
63
|
+
/** What a figure shows: the card and the change the question names. */
|
|
64
|
+
function factsOf(scene) {
|
|
65
|
+
return [
|
|
66
|
+
"card",
|
|
67
|
+
...((scene.flip ?? "none") !== "none" ? ["flip"] : []),
|
|
68
|
+
...((scene.turn ?? 0) !== 0 ? ["turn"] : []),
|
|
69
|
+
...(scene.swap ? ["swap"] : []),
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
function solve(scene, question, _givens, offered) {
|
|
73
|
+
if (!scene)
|
|
74
|
+
return noScene;
|
|
75
|
+
const answer = keyOf(change(scene.card, scene), false);
|
|
76
|
+
const what = question.ask === "mirror-image" ? "the card in the mirror" : "the card turned";
|
|
77
|
+
const choices = (offered?.choices ?? []);
|
|
78
|
+
return pick(choices, answer, (o) => keyOf(shownBy(o), false), factsOf(scene), what);
|
|
79
|
+
}
|
|
80
|
+
/** figureSolver picks the card after its change: the questions of FigureQuestion. */
|
|
81
|
+
export const figureSolver = {
|
|
82
|
+
name: "figure",
|
|
83
|
+
kinds: ["figure"],
|
|
84
|
+
questions: Object.keys(members),
|
|
85
|
+
check,
|
|
86
|
+
facts: factsOf,
|
|
87
|
+
solve,
|
|
88
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type FoldScene } from "../kinds/fold.ts";
|
|
2
|
+
import { type Solver } from "./proof.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The question about a sheet folded and punched, answered by the letter of
|
|
5
|
+
* the right one of the task's picture options, fold scenes with show
|
|
6
|
+
* "unfolded", each a sheet laid open.
|
|
7
|
+
*
|
|
8
|
+
* - `unfolded`: which option is the sheet opened again, a hole in each layer
|
|
9
|
+
* the punch went through, every hole and cut mirrored at each fold.
|
|
10
|
+
*
|
|
11
|
+
* Two sheets look the same when the kind lays them open the same: the same
|
|
12
|
+
* size, colour and grid, the same parts of squares cut away, and the same
|
|
13
|
+
* holes, each with its shape, its way and its square. The statement's
|
|
14
|
+
* picture folds the sheet at least once and punches or cuts it, and never
|
|
15
|
+
* draws it open: show "ask" or "steps". Two options that look the same are
|
|
16
|
+
* refused. It takes no givens.
|
|
17
|
+
*/
|
|
18
|
+
export type FoldQuestion = {
|
|
19
|
+
ask: "unfolded";
|
|
20
|
+
};
|
|
21
|
+
/** foldSolver opens a folded sheet: the question of FoldQuestion. */
|
|
22
|
+
export declare const foldSolver: Solver<FoldScene, FoldQuestion, Record<string, never>>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { unfold } from "../kinds/fold.js";
|
|
2
|
+
import { key } from "../kinds/fold-parts.js";
|
|
3
|
+
import { alike, choicesOf, pick, shows } from "./choice-scenes.js";
|
|
4
|
+
import { noScene } from "./proof.js";
|
|
5
|
+
import { askOf, noGivens, sceneless } from "./question.js";
|
|
6
|
+
const members = { unfolded: [] };
|
|
7
|
+
/** openOf names what a sheet looks like laid open, one name for sheets that look the same. */
|
|
8
|
+
function openOf(scene) {
|
|
9
|
+
const { atoms, holes } = unfold(scene);
|
|
10
|
+
const { rows, cols, color = "yellow", grid = false } = scene.sheet;
|
|
11
|
+
return JSON.stringify([
|
|
12
|
+
rows,
|
|
13
|
+
cols,
|
|
14
|
+
color,
|
|
15
|
+
grid,
|
|
16
|
+
atoms.map(key).sort((a, b) => a - b),
|
|
17
|
+
holes.map((h) => `${h.r} ${h.c} ${h.shape} ${h.turn}`).sort((a, b) => a.localeCompare(b)),
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
function check(question, givens, scene, offered) {
|
|
21
|
+
const problems = [];
|
|
22
|
+
noGivens(givens, problems);
|
|
23
|
+
const read = askOf(question, members, problems);
|
|
24
|
+
if (!read)
|
|
25
|
+
return problems;
|
|
26
|
+
const before = problems.length;
|
|
27
|
+
const choices = choicesOf(offered, read.ask, "fold", (o, path) => {
|
|
28
|
+
shows(o, path, "unfolded", "steps", problems);
|
|
29
|
+
}, problems);
|
|
30
|
+
if (problems.length === before)
|
|
31
|
+
alike(choices, openOf, problems);
|
|
32
|
+
if (!scene) {
|
|
33
|
+
sceneless(read.ask, "a scene of fold, the sheet folded", problems);
|
|
34
|
+
return problems;
|
|
35
|
+
}
|
|
36
|
+
if ((scene.folds ?? []).length === 0)
|
|
37
|
+
problems.push("folds: the sheet is not folded, so opening it changes nothing");
|
|
38
|
+
if ((scene.holes ?? []).length === 0 && (scene.cuts ?? []).length === 0)
|
|
39
|
+
problems.push("holes: the folded sheet is neither punched nor cut");
|
|
40
|
+
const show = scene.show ?? "steps";
|
|
41
|
+
if (show === "result" || show === "unfolded")
|
|
42
|
+
problems.push(`show: "${show}" draws the open sheet, the answer; show "ask" or "steps"`);
|
|
43
|
+
return problems;
|
|
44
|
+
}
|
|
45
|
+
/** The facts of a fold are the sheet, each fold, each hole and each cut. */
|
|
46
|
+
function facts(scene) {
|
|
47
|
+
return [
|
|
48
|
+
"sheet",
|
|
49
|
+
...(scene.folds ?? []).map((_, i) => `folds[${i}]`),
|
|
50
|
+
...(scene.holes ?? []).map((_, i) => `holes[${i}]`),
|
|
51
|
+
...(scene.cuts ?? []).map((_, i) => `cuts[${i}]`),
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
function solve(scene, _question, _givens, offered) {
|
|
55
|
+
if (!scene)
|
|
56
|
+
return noScene;
|
|
57
|
+
const choices = (offered?.choices ?? []);
|
|
58
|
+
return pick(choices, openOf(scene), openOf, facts(scene), "the sheet opened again");
|
|
59
|
+
}
|
|
60
|
+
/** foldSolver opens a folded sheet: the question of FoldQuestion. */
|
|
61
|
+
export const foldSolver = {
|
|
62
|
+
name: "fold",
|
|
63
|
+
kinds: ["fold"],
|
|
64
|
+
questions: Object.keys(members),
|
|
65
|
+
check,
|
|
66
|
+
facts,
|
|
67
|
+
solve,
|
|
68
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { LineScene } from "../kinds/line.ts";
|
|
2
|
+
import type { NecklaceScene } from "../kinds/necklace.ts";
|
|
3
|
+
import { type Solver } from "./proof.ts";
|
|
4
|
+
/**
|
|
5
|
+
* The questions of points and the gaps between them: posts of a fence,
|
|
6
|
+
* things in a row, holes of a strip, beads round a necklace or along a
|
|
7
|
+
* string, cuts across a log, flags on a number line. In a line there is one
|
|
8
|
+
* gap fewer than points, round a closed necklace as many gaps as beads, and a
|
|
9
|
+
* log has one piece more than its cut lines.
|
|
10
|
+
*
|
|
11
|
+
* - `gaps`: how many gaps the points make, a number — of the line, or of
|
|
12
|
+
* every necklace of the scene added up —, or that count times the amount
|
|
13
|
+
* each gap stands for, in metres or minutes. The amount is `per` of the
|
|
14
|
+
* givens, or the one the picture writes on the gaps it labels, every one the
|
|
15
|
+
* same; with both, they agree. A whole length the picture shows is "?",
|
|
16
|
+
* what the question asks. A fence, a row or a strip whose middle is not
|
|
17
|
+
* shown has as many points as `points` of the givens tells, or as the label
|
|
18
|
+
* of its last point says when its labels number the points from the first.
|
|
19
|
+
* - `points`: how many points stand on a line, a number. On a number line,
|
|
20
|
+
* the first two points stand at its two marks of one thing, and the others
|
|
21
|
+
* go on at the same step up to `to` of the givens, both ends counted. On a
|
|
22
|
+
* fence, a row or a strip, the points between the places `between` names,
|
|
23
|
+
* counted from the left, the two not counted; or every point — the line's
|
|
24
|
+
* own, or, where its middle is not shown, one more than `gaps` of the givens.
|
|
25
|
+
* - `cuts`: how many cuts a log's cut lines make, a number, or that count
|
|
26
|
+
* times `per` of the givens, the minutes a cut takes; `pieces` of the
|
|
27
|
+
* givens, where the statement tells them, are one more than the cuts.
|
|
28
|
+
* - `pieces`: how many pieces a log's cut lines make, a number; `cuts` of the
|
|
29
|
+
* givens, where the statement tells them, are the log's cut lines. Pieces
|
|
30
|
+
* that each show "?" are the ones the question counts.
|
|
31
|
+
*
|
|
32
|
+
* A length that is no whole number of steps has no answer.
|
|
33
|
+
*/
|
|
34
|
+
export type GapsQuestion = {
|
|
35
|
+
ask: "gaps";
|
|
36
|
+
} | {
|
|
37
|
+
ask: "points";
|
|
38
|
+
between?: [number, number];
|
|
39
|
+
} | {
|
|
40
|
+
ask: "cuts";
|
|
41
|
+
} | {
|
|
42
|
+
ask: "pieces";
|
|
43
|
+
};
|
|
44
|
+
/** What the statement tells besides the picture; which a question takes is in GapsQuestion. */
|
|
45
|
+
export type GapsGivens = {
|
|
46
|
+
per?: number;
|
|
47
|
+
points?: number;
|
|
48
|
+
gaps?: number;
|
|
49
|
+
to?: number;
|
|
50
|
+
pieces?: number;
|
|
51
|
+
cuts?: number;
|
|
52
|
+
};
|
|
53
|
+
export type GapsScene = LineScene | NecklaceScene;
|
|
54
|
+
/**
|
|
55
|
+
* lineFacts are the members of a line that show a fact: its points — each
|
|
56
|
+
* thing of a row, or the count of posts, holes, cut lines, ticks or steps —,
|
|
57
|
+
* the labels on its points and on its gaps where one is written, the lengths
|
|
58
|
+
* of its gaps, its whole length, each jump and each mark, and the middle it
|
|
59
|
+
* does not show.
|
|
60
|
+
*/
|
|
61
|
+
export declare function lineFacts(s: LineScene): string[];
|
|
62
|
+
/** necklaceFacts are each bead of every necklace, and its label and its cut where it has one. */
|
|
63
|
+
export declare function necklaceFacts(s: NecklaceScene): string[];
|
|
64
|
+
/** gapsSolver counts points, gaps, cuts and pieces: the questions of GapsQuestion. */
|
|
65
|
+
export declare const gapsSolver: Solver<GapsScene, GapsQuestion, GapsGivens>;
|