@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.
Files changed (130) hide show
  1. package/README.md +1 -1
  2. package/lib/index.d.ts +45 -1
  3. package/lib/index.js +34 -3
  4. package/lib/kinds/balance.js +2 -3
  5. package/lib/kinds/calendar.d.ts +5 -1
  6. package/lib/kinds/calendar.js +33 -11
  7. package/lib/kinds/chart.js +2 -4
  8. package/lib/kinds/clock.d.ts +5 -0
  9. package/lib/kinds/clock.js +45 -4
  10. package/lib/kinds/coins.js +3 -2
  11. package/lib/kinds/column.js +2 -3
  12. package/lib/kinds/commands.d.ts +8 -6
  13. package/lib/kinds/commands.js +57 -15
  14. package/lib/kinds/containers.js +2 -1
  15. package/lib/kinds/countfig.d.ts +2 -0
  16. package/lib/kinds/countfig.js +6 -1
  17. package/lib/kinds/cubes.d.ts +29 -5
  18. package/lib/kinds/cubes.js +82 -34
  19. package/lib/kinds/die.d.ts +8 -0
  20. package/lib/kinds/die.js +75 -14
  21. package/lib/kinds/domino.js +3 -3
  22. package/lib/kinds/dotgrid.d.ts +3 -0
  23. package/lib/kinds/dotgrid.js +6 -4
  24. package/lib/kinds/figure.js +5 -4
  25. package/lib/kinds/fold-parts.d.ts +0 -2
  26. package/lib/kinds/fold-parts.js +0 -4
  27. package/lib/kinds/fold.d.ts +20 -1
  28. package/lib/kinds/fold.js +15 -6
  29. package/lib/kinds/fraction.js +3 -2
  30. package/lib/kinds/gauges.js +2 -1
  31. package/lib/kinds/gears.d.ts +21 -2
  32. package/lib/kinds/gears.js +113 -62
  33. package/lib/kinds/grid.d.ts +5 -0
  34. package/lib/kinds/grid.js +30 -2
  35. package/lib/kinds/groups.d.ts +3 -1
  36. package/lib/kinds/groups.js +142 -28
  37. package/lib/kinds/lanes.js +3 -2
  38. package/lib/kinds/layers.d.ts +6 -0
  39. package/lib/kinds/layers.js +23 -4
  40. package/lib/kinds/line.d.ts +4 -0
  41. package/lib/kinds/line.js +117 -32
  42. package/lib/kinds/matchsticks.d.ts +4 -0
  43. package/lib/kinds/matchsticks.js +5 -3
  44. package/lib/kinds/net.js +4 -3
  45. package/lib/kinds/overlay.d.ts +23 -1
  46. package/lib/kinds/overlay.js +7 -3
  47. package/lib/kinds/pieces.js +3 -2
  48. package/lib/kinds/plane-parts.d.ts +0 -2
  49. package/lib/kinds/plane-parts.js +0 -6
  50. package/lib/kinds/plane.js +6 -6
  51. package/lib/kinds/ropes.js +1 -3
  52. package/lib/kinds/shapes.js +5 -7
  53. package/lib/kinds/solids.js +3 -2
  54. package/lib/kinds/tangram.js +2 -4
  55. package/lib/kinds/target.js +4 -6
  56. package/lib/kinds/tiles.js +5 -4
  57. package/lib/kinds/venn.js +3 -5
  58. package/lib/noto.js +1 -0
  59. package/lib/objects.js +2 -1
  60. package/lib/read.d.ts +2 -2
  61. package/lib/read.js +3 -3
  62. package/lib/solve/balance.d.ts +11 -0
  63. package/lib/solve/balance.js +116 -1
  64. package/lib/solve/calendar.d.ts +46 -0
  65. package/lib/solve/calendar.js +206 -0
  66. package/lib/solve/choice-scenes.d.ts +20 -0
  67. package/lib/solve/choice-scenes.js +51 -0
  68. package/lib/solve/clock.d.ts +54 -0
  69. package/lib/solve/clock.js +240 -0
  70. package/lib/solve/coins.d.ts +71 -0
  71. package/lib/solve/coins.js +222 -0
  72. package/lib/solve/commands.d.ts +36 -0
  73. package/lib/solve/commands.js +210 -0
  74. package/lib/solve/countfig.d.ts +41 -0
  75. package/lib/solve/countfig.js +199 -0
  76. package/lib/solve/cubes.d.ts +49 -0
  77. package/lib/solve/cubes.js +255 -0
  78. package/lib/solve/die.d.ts +39 -0
  79. package/lib/solve/die.js +93 -0
  80. package/lib/solve/domino.d.ts +57 -0
  81. package/lib/solve/domino.js +263 -0
  82. package/lib/solve/enumerate.d.ts +75 -0
  83. package/lib/solve/enumerate.js +323 -0
  84. package/lib/solve/figure.d.ts +26 -0
  85. package/lib/solve/figure.js +88 -0
  86. package/lib/solve/fold.d.ts +22 -0
  87. package/lib/solve/fold.js +68 -0
  88. package/lib/solve/gaps.d.ts +65 -0
  89. package/lib/solve/gaps.js +292 -0
  90. package/lib/solve/gears.d.ts +33 -0
  91. package/lib/solve/gears.js +130 -0
  92. package/lib/solve/grid.d.ts +35 -0
  93. package/lib/solve/grid.js +194 -0
  94. package/lib/solve/groups.d.ts +93 -0
  95. package/lib/solve/groups.js +346 -0
  96. package/lib/solve/index.d.ts +60 -0
  97. package/lib/solve/index.js +194 -0
  98. package/lib/solve/layers.d.ts +30 -0
  99. package/lib/solve/layers.js +72 -0
  100. package/lib/solve/magic.d.ts +32 -0
  101. package/lib/solve/magic.js +216 -0
  102. package/lib/solve/matchsticks.d.ts +37 -0
  103. package/lib/solve/matchsticks.js +214 -0
  104. package/lib/solve/order.d.ts +94 -0
  105. package/lib/solve/order.js +419 -0
  106. package/lib/solve/overlay.d.ts +22 -0
  107. package/lib/solve/overlay.js +56 -0
  108. package/lib/solve/parity.d.ts +22 -0
  109. package/lib/solve/parity.js +27 -0
  110. package/lib/solve/pattern.d.ts +62 -0
  111. package/lib/solve/pattern.js +533 -0
  112. package/lib/solve/pieces.d.ts +57 -0
  113. package/lib/solve/pieces.js +309 -0
  114. package/lib/solve/pigeonhole.d.ts +38 -0
  115. package/lib/solve/pigeonhole.js +95 -0
  116. package/lib/solve/proof.d.ts +115 -0
  117. package/lib/solve/proof.js +105 -0
  118. package/lib/solve/pyramid.d.ts +28 -0
  119. package/lib/solve/pyramid.js +161 -0
  120. package/lib/solve/question.d.ts +25 -0
  121. package/lib/solve/question.js +75 -0
  122. package/lib/solve/shapes.d.ts +30 -0
  123. package/lib/solve/shapes.js +182 -0
  124. package/lib/solve/target.d.ts +40 -0
  125. package/lib/solve/target.js +190 -0
  126. package/lib/style.d.ts +1 -1
  127. package/lib/style.js +1 -1
  128. package/lib/words.d.ts +15 -0
  129. package/lib/words.js +39 -0
  130. package/package.json +1 -1
@@ -0,0 +1,419 @@
1
+ import { isObject } from "../objects.js";
2
+ import { int, isObj, list, oneOf, only, text } from "../read.js";
3
+ import { checkThing, wordOf } from "../things.js";
4
+ import { say, solved, unsolved } from "./proof.js";
5
+ import { askOf, flagOf } from "./question.js";
6
+ const members = {
7
+ first: [],
8
+ last: [],
9
+ "at-place": [],
10
+ "place-of": [],
11
+ "line-length": [],
12
+ };
13
+ const most = 6;
14
+ const clueMost = 8;
15
+ const eventMost = 4;
16
+ const relations = ["ahead", "behind", "right-ahead", "right-behind", "at", "not-at"];
17
+ const doings = ["passes", "leaves", "joins"];
18
+ const placeLabel = /^([1-9][0-9]?)(st|nd|rd|th)$/;
19
+ /** The members of a line the order reads: its things and their labels. */
20
+ const rowMembers = ["kind", "style", "things", "labels"];
21
+ /** ordinal writes a place as a label writes it: 1st, 2nd, 3rd, 4th, 11th. */
22
+ function ordinal(p) {
23
+ const teen = p % 100 >= 11 && p % 100 <= 13;
24
+ const end = teen ? "th" : p % 10 === 1 ? "st" : p % 10 === 2 ? "nd" : p % 10 === 3 ? "rd" : "th";
25
+ return `${p}${end}`;
26
+ }
27
+ /** permutations gives every order of the items, each once. */
28
+ export function* permutations(items) {
29
+ if (items.length <= 1) {
30
+ yield [...items];
31
+ return;
32
+ }
33
+ for (let i = 0; i < items.length; i++) {
34
+ const rest = [...items.slice(0, i), ...items.slice(i + 1)];
35
+ for (const tail of permutations(rest))
36
+ yield [items[i], ...tail];
37
+ }
38
+ }
39
+ const keyOf = (v) => JSON.stringify(v);
40
+ const isAsk = (t) => typeof t === "object" && "ask" in t;
41
+ const isEmpty = (t) => typeof t === "object" && "empty" in t;
42
+ /** named is what a who of the givens names: a name, or a thing. */
43
+ function named(who) {
44
+ return typeof who === "string" && !isObject(who) ? { text: who } : { thing: who };
45
+ }
46
+ function checkWho(value, path, problems) {
47
+ const before = problems.length;
48
+ if (typeof value === "string" && !isObject(value))
49
+ text(value, path, problems, 12);
50
+ else
51
+ checkThing(value, path, problems);
52
+ if (problems.length > before)
53
+ return false;
54
+ if (isObj(value) && (value.ask === true || value.empty === true)) {
55
+ problems.push(`${path}: must name a child or an animal, not ${wordOf(value)}`);
56
+ return false;
57
+ }
58
+ return true;
59
+ }
60
+ /**
61
+ * find is the person a who names among people: by its name, or by its
62
+ * thing where one person has that thing.
63
+ */
64
+ function find(who, people, among, path, problems) {
65
+ const v = named(who);
66
+ const k = keyOf(v);
67
+ const byValue = among.filter((i) => keyOf(people[i].value) === k);
68
+ if (byValue.length === 1)
69
+ return byValue[0];
70
+ if ("thing" in v) {
71
+ const byThing = among.filter((i) => {
72
+ const t = people[i].thing;
73
+ return t !== undefined && JSON.stringify(t) === JSON.stringify(v.thing);
74
+ });
75
+ if (byThing.length === 1)
76
+ return byThing[0];
77
+ if (byThing.length > 1) {
78
+ problems.push(`${path}: more than one in the line is ${wordOf(v.thing)}; name one`);
79
+ return undefined;
80
+ }
81
+ }
82
+ problems.push(`${path}: ${say(v)} is not in the line`);
83
+ return undefined;
84
+ }
85
+ function startOf(scene, g, problems) {
86
+ const people = [];
87
+ const add = (p, path) => {
88
+ if (people.some((o) => keyOf(o.value) === keyOf(p.value))) {
89
+ problems.push(`${path}: ${say(p.value)} is in the line twice`);
90
+ return undefined;
91
+ }
92
+ people.push(p);
93
+ return people.length - 1;
94
+ };
95
+ if (!scene) {
96
+ for (const m of ["fill", "marker"])
97
+ if (g[m] !== undefined)
98
+ problems.push(`givens.${m}: is for a row the scene draws`);
99
+ if (g.children === undefined) {
100
+ problems.push("givens.children: name everyone in the order, as there is no scene");
101
+ return undefined;
102
+ }
103
+ const before = problems.length;
104
+ const kids = list(g.children, "givens.children", problems, 2, most);
105
+ const fills = [];
106
+ kids.forEach((c, i) => {
107
+ const path = `givens.children[${i}]`;
108
+ if (!checkWho(c, path, problems))
109
+ return;
110
+ const at = add({ value: named(c) }, path);
111
+ if (at !== undefined)
112
+ fills.push(at);
113
+ });
114
+ if (problems.length > before)
115
+ return undefined;
116
+ return { people, slots: fills.map(() => undefined), fills };
117
+ }
118
+ if (g.children !== undefined)
119
+ problems.push("givens.children: the row is the start order; name who fills it in fill");
120
+ const before = problems.length;
121
+ if (scene.style !== "row")
122
+ problems.push(`style: order reads a row of things, not ${scene.style}`);
123
+ for (const key of Object.keys(scene))
124
+ if (!rowMembers.includes(key))
125
+ problems.push(`${key}: order reads the row's things and labels, not its ${key}`);
126
+ flagOf(g.marker, "givens.marker", problems);
127
+ if (problems.length > before)
128
+ return undefined;
129
+ const things = scene.things;
130
+ const labels = scene.labels ?? [];
131
+ const front = g.marker === true ? 1 : 0;
132
+ if (front === 1) {
133
+ const t = things[0];
134
+ if (isAsk(t) || isEmpty(t))
135
+ problems.push(`things[0]: marks the front, so it must be a thing, not ${wordOf(t)}`);
136
+ if (labels[0])
137
+ problems.push("labels[0]: the thing that marks the front stands in no place");
138
+ }
139
+ const slots = [];
140
+ for (let i = front; i < things.length; i++) {
141
+ const t = things[i];
142
+ const label = labels[i] ?? "";
143
+ const place = i - front + 1;
144
+ const ordinalLabel = placeLabel.test(label);
145
+ if (ordinalLabel && label !== ordinal(place))
146
+ problems.push(`labels[${i}]: ${label} stands on the ${ordinal(place)} place`);
147
+ if (isEmpty(t)) {
148
+ problems.push(`things[${i}]: an empty place is no one in the line`);
149
+ continue;
150
+ }
151
+ if (isAsk(t)) {
152
+ if (label !== "" && !ordinalLabel)
153
+ problems.push(`labels[${i}]: a question mark is a place to fill, and carries no name`);
154
+ slots.push(undefined);
155
+ continue;
156
+ }
157
+ const value = label !== "" && !ordinalLabel ? { text: label } : { thing: t };
158
+ slots.push(add({ value, thing: t }, `things[${i}]`) ?? -1);
159
+ }
160
+ if (slots.length < 2)
161
+ problems.push("things: a line needs two or more in it");
162
+ const holes = slots.filter((s) => s === undefined).length;
163
+ const fills = [];
164
+ if (holes === 0 && g.fill !== undefined)
165
+ problems.push("givens.fill: the row has no question mark to fill");
166
+ if (holes > 0) {
167
+ if (g.fill === undefined)
168
+ problems.push(`givens.fill: name who stands in the row's ${holes} question marks`);
169
+ else {
170
+ const fill = list(g.fill, "givens.fill", problems);
171
+ if (Array.isArray(g.fill) && g.fill.length !== holes)
172
+ problems.push(`givens.fill: must name exactly ${holes}, one for each question mark`);
173
+ fill.forEach((c, i) => {
174
+ const path = `givens.fill[${i}]`;
175
+ if (!checkWho(c, path, problems))
176
+ return;
177
+ const at = add({ value: named(c) }, path);
178
+ if (at !== undefined)
179
+ fills.push(at);
180
+ });
181
+ }
182
+ }
183
+ if (holes > most)
184
+ problems.push(`things: at most ${most} question marks for the solver`);
185
+ if (problems.length > before)
186
+ return undefined;
187
+ return { people, slots, fills };
188
+ }
189
+ function readClues(g, start, problems) {
190
+ if (g.clues === undefined)
191
+ return [];
192
+ const out = [];
193
+ const all = start.people.map((_, i) => i);
194
+ const n = start.slots.length;
195
+ list(g.clues, "givens.clues", problems, 1, clueMost).forEach((c, i) => {
196
+ const path = `givens.clues[${i}]`;
197
+ if (!isObj(c)) {
198
+ problems.push(`${path}: must be a clue, as {"who": "Ana", "is": "ahead", "of": "Mei"}`);
199
+ return;
200
+ }
201
+ const before = problems.length;
202
+ const is = oneOf(c.is, relations, `${path}.is`, problems);
203
+ if (problems.length > before)
204
+ return;
205
+ const place = is === "at" || is === "not-at";
206
+ only(c, ["who", "is", place ? "place" : "of"], path, problems, `a clue ${is}`);
207
+ const who = checkWho(c.who, `${path}.who`, problems)
208
+ ? find(c.who, start.people, all, `${path}.who`, problems)
209
+ : undefined;
210
+ if (place) {
211
+ if (c.place !== "last")
212
+ int(c.place, `${path}.place`, problems, 1, n);
213
+ if (who !== undefined && problems.length === before)
214
+ out.push({ who, is, place: c.place });
215
+ return;
216
+ }
217
+ const of = checkWho(c.of, `${path}.of`, problems)
218
+ ? find(c.of, start.people, all, `${path}.of`, problems)
219
+ : undefined;
220
+ if (who !== undefined && who === of)
221
+ problems.push(`${path}.of: is the same as who`);
222
+ if (who !== undefined && of !== undefined && problems.length === before)
223
+ out.push({ who, is: is, of });
224
+ });
225
+ return out;
226
+ }
227
+ function readEvents(g, start, problems) {
228
+ const inLine = start.people.map((_, i) => i);
229
+ if (g.events === undefined)
230
+ return { events: [], in: inLine };
231
+ const out = [];
232
+ list(g.events, "givens.events", problems, 1, eventMost).forEach((e, i) => {
233
+ const path = `givens.events[${i}]`;
234
+ if (!isObj(e)) {
235
+ problems.push(`${path}: must be an event, as {"who": "Raj", "does": "leaves"}`);
236
+ return;
237
+ }
238
+ const before = problems.length;
239
+ const does = oneOf(e.does, doings, `${path}.does`, problems);
240
+ if (problems.length > before)
241
+ return;
242
+ only(e, ["who", "does", ...(does === "passes" ? ["whom"] : [])], path, problems, `an event ${does}`);
243
+ if (!checkWho(e.who, `${path}.who`, problems))
244
+ return;
245
+ if (does === "joins") {
246
+ const value = named(e.who);
247
+ if (start.people.some((p) => keyOf(p.value) === keyOf(value))) {
248
+ problems.push(`${path}.who: ${say(value)} is in the line already, or was`);
249
+ return;
250
+ }
251
+ start.people.push({ value });
252
+ const at = start.people.length - 1;
253
+ inLine.push(at);
254
+ if (problems.length === before)
255
+ out.push({ who: at, does });
256
+ return;
257
+ }
258
+ const who = find(e.who, start.people, inLine, `${path}.who`, problems);
259
+ if (does === "leaves") {
260
+ if (who !== undefined) {
261
+ inLine.splice(inLine.indexOf(who), 1);
262
+ if (problems.length === before)
263
+ out.push({ who, does });
264
+ }
265
+ return;
266
+ }
267
+ const whom = checkWho(e.whom, `${path}.whom`, problems)
268
+ ? find(e.whom, start.people, inLine, `${path}.whom`, problems)
269
+ : undefined;
270
+ if (who !== undefined && who === whom)
271
+ problems.push(`${path}.whom: is the same as who`);
272
+ if (who !== undefined && whom !== undefined && problems.length === before)
273
+ out.push({ who, does, whom });
274
+ });
275
+ return { events: out, in: inLine };
276
+ }
277
+ function readGivens(ask, givens, scene, problems) {
278
+ const g = givens === undefined ? {} : isObj(givens) ? givens : {};
279
+ if (givens !== undefined && !isObj(givens)) {
280
+ problems.push("givens: must be an object");
281
+ return undefined;
282
+ }
283
+ if (ask === "line-length") {
284
+ only(g, ["fromFront", "fromBack"], "givens", problems, "the givens of line-length");
285
+ if (scene)
286
+ problems.push("scene: line-length reads no scene; the statement tells the places");
287
+ int(g.fromFront, "givens.fromFront", problems, 1, 12);
288
+ int(g.fromBack, "givens.fromBack", problems, 1, 12);
289
+ return undefined;
290
+ }
291
+ const own = ask === "at-place" ? ["place"] : ask === "place-of" ? ["child"] : [];
292
+ only(g, ["children", "fill", "marker", "clues", "events", ...own], "givens", problems, `the givens of ${ask}`);
293
+ const start = startOf(scene, g, problems);
294
+ if (!start)
295
+ return undefined;
296
+ const clues = readClues(g, start, problems);
297
+ const { events, in: after } = readEvents(g, start, problems);
298
+ const read = { start, clues, events };
299
+ if (ask === "at-place") {
300
+ const before = problems.length;
301
+ const place = int(g.place, "givens.place", problems, 1, Math.max(1, after.length));
302
+ if (problems.length === before)
303
+ read.place = place;
304
+ }
305
+ if (ask === "place-of") {
306
+ if (g.child === undefined)
307
+ problems.push("givens.child: name the one whose place is asked");
308
+ else if (checkWho(g.child, "givens.child", problems)) {
309
+ const child = find(g.child, start.people, after, "givens.child", problems);
310
+ if (child !== undefined)
311
+ read.child = child;
312
+ }
313
+ }
314
+ if (after.length === 0)
315
+ problems.push("givens.events: no one is left in the line");
316
+ return read;
317
+ }
318
+ function check(question, givens, scene) {
319
+ const problems = [];
320
+ const read = askOf(question, members, problems);
321
+ if (!read)
322
+ return problems;
323
+ readGivens(read.ask, givens, scene, problems);
324
+ return problems;
325
+ }
326
+ /** keeps tells whether an order keeps a clue. */
327
+ function keeps(line, clue) {
328
+ const at = line.indexOf(clue.who);
329
+ if ("place" in clue) {
330
+ const place = clue.place === "last" ? line.length - 1 : clue.place - 1;
331
+ return clue.is === "at" ? at === place : at !== place;
332
+ }
333
+ const of = line.indexOf(clue.of);
334
+ switch (clue.is) {
335
+ case "ahead":
336
+ return at < of;
337
+ case "behind":
338
+ return at > of;
339
+ case "right-ahead":
340
+ return at === of - 1;
341
+ default:
342
+ return at === of + 1;
343
+ }
344
+ }
345
+ /** happen applies the events to an order; undefined when a pass cannot happen in it. */
346
+ function happen(start, events) {
347
+ const line = [...start];
348
+ for (const e of events) {
349
+ if (e.does === "joins")
350
+ line.push(e.who);
351
+ else if (e.does === "leaves")
352
+ line.splice(line.indexOf(e.who), 1);
353
+ else {
354
+ const at = line.indexOf(e.who);
355
+ const ahead = line.indexOf(e.whom);
356
+ if (ahead > at)
357
+ return undefined;
358
+ line.splice(at, 1);
359
+ line.splice(ahead, 0, e.who);
360
+ }
361
+ }
362
+ return line;
363
+ }
364
+ function answerOf(ask, line, r) {
365
+ const people = r.start.people;
366
+ if (ask === "first")
367
+ return people[line[0]].value;
368
+ if (ask === "last")
369
+ return people[line[line.length - 1]].value;
370
+ if (ask === "at-place")
371
+ return people[line[r.place - 1]].value;
372
+ return { number: line.indexOf(r.child) + 1 };
373
+ }
374
+ function solve(scene, question, givens) {
375
+ const reads = scene ? facts(scene) : [];
376
+ if (question.ask === "line-length")
377
+ return solved({ number: givens.fromFront + givens.fromBack - 1 }, reads);
378
+ const r = readGivens(question.ask, givens, scene, []);
379
+ const answers = new Map();
380
+ let fitting = 0;
381
+ for (const fill of permutations(r.start.fills)) {
382
+ let k = 0;
383
+ const start = r.start.slots.map((s) => s ?? fill[k++]);
384
+ if (!r.clues.every((c) => keeps(start, c)))
385
+ continue;
386
+ const line = happen(start, r.events);
387
+ if (!line)
388
+ continue;
389
+ fitting++;
390
+ const value = answerOf(question.ask, line, r);
391
+ answers.set(keyOf(value), value);
392
+ }
393
+ if (fitting === 0)
394
+ return unsolved("no order keeps every clue and lets every pass happen", reads);
395
+ const found = [...answers.values()];
396
+ if (found.length === 1)
397
+ return solved(found[0], reads);
398
+ return unsolved(`${fitting} orders keep every clue, and they answer ${found.map(say).join(" or ")}`, reads, found);
399
+ }
400
+ /** The facts of a row are its things and their labels. */
401
+ function facts(scene) {
402
+ return [
403
+ ...(scene.things ?? []).map((_, i) => `things[${i}]`),
404
+ ...(scene.labels ?? []).flatMap((l, i) => (l === "" ? [] : [`labels[${i}]`])),
405
+ ];
406
+ }
407
+ /**
408
+ * orderSolver joins the clues about an order of children or animals: the
409
+ * questions of OrderQuestion, the start order read from a row of a line or
410
+ * told in givens.children.
411
+ */
412
+ export const orderSolver = {
413
+ name: "order",
414
+ kinds: ["line"],
415
+ questions: Object.keys(members),
416
+ check,
417
+ facts,
418
+ solve,
419
+ };
@@ -0,0 +1,22 @@
1
+ import { type OverlayScene } from "../kinds/overlay.ts";
2
+ import { type Solver } from "./proof.ts";
3
+ /**
4
+ * The question about transparent cards laid one on another, answered by
5
+ * the letter of the right one of the task's picture options, overlay scenes
6
+ * with show "together", each a view drawn as one card.
7
+ *
8
+ * - `seen-together`: which option is what is seen through the cards laid in
9
+ * order, each flipped and turned as it says, the first at the bottom; the
10
+ * marks are opaque, so where two lie on each other the upper is seen.
11
+ *
12
+ * Two views look the same when the kind lays their cards together the same:
13
+ * the same size, and every part of a square filled with the same colour and
14
+ * every shape the same, with its colour and its way, in the same square.
15
+ * The statement's picture never draws the view: show "ask" or "cards". Two
16
+ * options that look the same are refused. It takes no givens.
17
+ */
18
+ export type OverlayQuestion = {
19
+ ask: "seen-together";
20
+ };
21
+ /** overlaySolver lays transparent cards together: the question of OverlayQuestion. */
22
+ export declare const overlaySolver: Solver<OverlayScene, OverlayQuestion, Record<string, never>>;
@@ -0,0 +1,56 @@
1
+ import { together } from "../kinds/overlay.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 = { "seen-together": [] };
6
+ /** viewOf names what is seen through the cards laid together, one name for views alike. */
7
+ function viewOf(scene) {
8
+ const laid = together(scene);
9
+ const fills = [...laid.fills]
10
+ .map(([k, f]) => `${k} ${f.color}`)
11
+ .sort((a, b) => a.localeCompare(b));
12
+ const shapes = [...laid.shapes]
13
+ .map(([at, m]) => `${at} ${m.shape} ${m.color} ${m.turn}`)
14
+ .sort((a, b) => a.localeCompare(b));
15
+ return JSON.stringify([scene.rows, scene.cols, fills, shapes]);
16
+ }
17
+ function check(question, givens, scene, offered) {
18
+ const problems = [];
19
+ noGivens(givens, problems);
20
+ const read = askOf(question, members, problems);
21
+ if (!read)
22
+ return problems;
23
+ const before = problems.length;
24
+ const choices = choicesOf(offered, read.ask, "overlay", (o, path) => {
25
+ shows(o, path, "together", "ask", problems);
26
+ }, problems);
27
+ if (problems.length === before)
28
+ alike(choices, viewOf, problems);
29
+ if (!scene) {
30
+ sceneless(read.ask, "a scene of overlay, the cards", problems);
31
+ return problems;
32
+ }
33
+ const show = scene.show ?? "ask";
34
+ if (show === "result" || show === "together")
35
+ problems.push(`show: "${show}" draws the view, the answer; show "ask" or "cards"`);
36
+ return problems;
37
+ }
38
+ /** The facts of cards laid together are the cards, each with its marks and its move. */
39
+ function facts(scene) {
40
+ return scene.cards.map((_, i) => `cards[${i}]`);
41
+ }
42
+ function solve(scene, _question, _givens, offered) {
43
+ if (!scene)
44
+ return noScene;
45
+ const choices = (offered?.choices ?? []);
46
+ return pick(choices, viewOf(scene), viewOf, facts(scene), "the cards seen together");
47
+ }
48
+ /** overlaySolver lays transparent cards together: the question of OverlayQuestion. */
49
+ export const overlaySolver = {
50
+ name: "overlay",
51
+ kinds: ["overlay"],
52
+ questions: Object.keys(members),
53
+ check,
54
+ facts,
55
+ solve,
56
+ };
@@ -0,0 +1,22 @@
1
+ import { type Solver } from "./proof.ts";
2
+ /**
3
+ * The question of two kinds that take turns all the way round a ring — red
4
+ * and blue plates round a table —, which the statement tells in words and no
5
+ * scene draws.
6
+ *
7
+ * - `ring-size`: how many places the ring has, a number. Round a ring that
8
+ * closes, the place before the first of one kind holds the other kind, so
9
+ * each place of one kind has a place of the other kind of its own: the two
10
+ * kinds are as many, and the ring holds twice the count the statement gives.
11
+ *
12
+ * Its givens are `count`, how many places hold one of the two kinds, 1 to
13
+ * 10, so that the ring holds 20 places at most.
14
+ */
15
+ export type ParityQuestion = {
16
+ ask: "ring-size";
17
+ };
18
+ export type ParityGivens = {
19
+ count: number;
20
+ };
21
+ /** paritySolver answers from the statement alone, so it reads no scene: the questions of ParityQuestion. */
22
+ export declare const paritySolver: Solver<undefined, ParityQuestion, ParityGivens>;
@@ -0,0 +1,27 @@
1
+ import { int, isObj, only } from "../read.js";
2
+ import { solved } from "./proof.js";
3
+ import { askOf } from "./question.js";
4
+ const members = { "ring-size": [] };
5
+ function check(question, givens) {
6
+ const problems = [];
7
+ askOf(question, members, problems);
8
+ if (!isObj(givens)) {
9
+ problems.push('givens: must be an object with count, as {"count": 7}');
10
+ return problems;
11
+ }
12
+ only(givens, ["count"], "givens", problems, "the givens of ring-size");
13
+ int(givens.count, "givens.count", problems, 1, 10);
14
+ return problems;
15
+ }
16
+ function solve(_scene, _question, givens) {
17
+ return solved({ number: 2 * givens.count }, []);
18
+ }
19
+ /** paritySolver answers from the statement alone, so it reads no scene: the questions of ParityQuestion. */
20
+ export const paritySolver = {
21
+ name: "parity",
22
+ kinds: [],
23
+ questions: Object.keys(members),
24
+ check,
25
+ facts: () => [],
26
+ solve,
27
+ };
@@ -0,0 +1,62 @@
1
+ import type { LineScene } from "../kinds/line.ts";
2
+ import type { NecklaceScene } from "../kinds/necklace.ts";
3
+ import { type TilesScene } from "../kinds/tiles.ts";
4
+ import { type Thing } from "../things.ts";
5
+ import { type Solver } from "./proof.ts";
6
+ /**
7
+ * The questions of a row that repeats a part or grows by a step: things in a
8
+ * row (a line of style row), the beads of one string or necklace, tiles in a
9
+ * row or round a ring. A closed necklace with no clasp, and a ring of tiles,
10
+ * go round: the part that repeats runs on across the top, so it fits the ring
11
+ * a whole number of times. A string, and a necklace read from its clasp, run
12
+ * from the first place to the last.
13
+ *
14
+ * The solver keeps every rule that agrees with each place the picture
15
+ * fills: a part of 1 to 4 that repeats, which the row shows whole once and
16
+ * then again but for its last place — red, blue, red for a part of two; a
17
+ * part of one shows twice —; or, from three places shown, a steady step:
18
+ * numbers that grow or shrink by the same amount, a turn round the tile by
19
+ * the same steps. A tile is read by its shape, its colours, its turn and its
20
+ * dots, each by a rule of its own, so that a mark that moves while its colour
21
+ * changes follows two rules at once. A question is proved when its rules give
22
+ * one answer; a row no rule tells has none, and the different answers of
23
+ * rules that disagree are its candidates, so that "it cannot be told" matches.
24
+ *
25
+ * - `next-in-row`: what stands at the "?" that ends a row: a thing; a number,
26
+ * for a row of number cards or of tiles of dots; or, for a row of tiles
27
+ * whose options are pictures, the letter of the task's picture option that
28
+ * draws it, each a tiles scene of one tile of the row's shape, which a row
29
+ * of tiles but for dots needs.
30
+ * - `missing-in-row`: what stands at a "?" that does not end a row, or at a
31
+ * "?" round a ring, answered as next-in-row is.
32
+ * - `at-place`: what stands at the place `place` of the givens, counted from
33
+ * the start, 1 to 20, past what the row draws: an empty place, a place after
34
+ * the row, or a "?" that ends the row standing for it; answered as
35
+ * next-in-row is. A tile's label that is a number names its place.
36
+ * - `how-many-of`: how many places of the row hold the thing `of`, a number,
37
+ * once its empty places are filled by its part, or once it runs on to
38
+ * `length` of the givens.
39
+ * - `part-of-ring`: which labelled string can be read on the closed necklace
40
+ * that comes first, from any bead, either way round, a text: its label.
41
+ * - `lands-on`: how many places of a row a jumper lands on, from the place
42
+ * its first jump starts at, on by the jump's step to the last place it
43
+ * reaches, a number; with `not`, how many places it never lands on. Its
44
+ * jumps, one or more, each go on from where the one before lands.
45
+ */
46
+ export type PatternQuestion = {
47
+ ask: "next-in-row" | "missing-in-row" | "at-place" | "part-of-ring";
48
+ } | {
49
+ ask: "how-many-of";
50
+ of: Thing;
51
+ } | {
52
+ ask: "lands-on";
53
+ not?: boolean;
54
+ };
55
+ /** What the statement tells besides the picture; which a question takes is in PatternQuestion. */
56
+ export type PatternGivens = {
57
+ place?: number;
58
+ length?: number;
59
+ };
60
+ export type PatternScene = LineScene | NecklaceScene | TilesScene;
61
+ /** patternSolver continues rows that repeat a part or grow by a step: the questions of PatternQuestion. */
62
+ export declare const patternSolver: Solver<PatternScene, PatternQuestion, PatternGivens>;