@altnovatrail/picture-kit 0.1.0 → 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 +2 -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,57 @@
|
|
|
1
|
+
import type { ChoicesScene } from "../kinds/choices.ts";
|
|
2
|
+
import type { DominoScene } from "../kinds/domino.ts";
|
|
3
|
+
import { type Solver } from "./proof.ts";
|
|
4
|
+
/**
|
|
5
|
+
* The questions about domino tiles, each half 0 to 9 dots, "?" where the
|
|
6
|
+
* question asks, or "cloud" for a half hidden under a cloud. Two read tiles
|
|
7
|
+
* offered as options — each a domino scene of one tile, both halves showing
|
|
8
|
+
* their dots —, the options of a scene of choices or, with no scene, the
|
|
9
|
+
* task's picture options, and answer with an option's letter, A for the
|
|
10
|
+
* first; the others read a domino scene.
|
|
11
|
+
*
|
|
12
|
+
* - `most-pips` (choices): the tile with the most dots, or with fewest the
|
|
13
|
+
* fewest. A tie has no answer.
|
|
14
|
+
* - `odd-one-out` (choices): the one tile whose total of dots differs from
|
|
15
|
+
* the total all the others share; givens.property names what the
|
|
16
|
+
* statement compares, "total". A scene of tiles where none differs, or
|
|
17
|
+
* more than one, is refused.
|
|
18
|
+
* - `chain-half` (a chain or a ring): the dots of the asked half — the one
|
|
19
|
+
* "?", or with none the one cloud —, which equal the half it touches, a
|
|
20
|
+
* number. Every other pair of touching halves must match.
|
|
21
|
+
* - `missing-tile` (a chain or a ring): which of the task's picture
|
|
22
|
+
* options, each a tile, fills the gap, the one tile ["?", "?"], a letter:
|
|
23
|
+
* it matches the half on either side of the gap, either way round. Every
|
|
24
|
+
* other pair of touching halves must match, and no two options are the
|
|
25
|
+
* same tile turned round.
|
|
26
|
+
* - `hidden-half`: the dots under one cloud, from the total of every tile,
|
|
27
|
+
* givens.total, and the dots in sight; with more than one cloud,
|
|
28
|
+
* givens.same says that they hide the same. A share that is not whole, or
|
|
29
|
+
* more than 9, has no answer.
|
|
30
|
+
*
|
|
31
|
+
* In a chain a tile's second half touches the next tile's first, and in a
|
|
32
|
+
* ring the last tile's second touches the first tile's first too.
|
|
33
|
+
*/
|
|
34
|
+
export type DominoQuestion = {
|
|
35
|
+
ask: "most-pips";
|
|
36
|
+
fewest?: boolean;
|
|
37
|
+
} | {
|
|
38
|
+
ask: "odd-one-out";
|
|
39
|
+
} | {
|
|
40
|
+
ask: "chain-half";
|
|
41
|
+
} | {
|
|
42
|
+
ask: "missing-tile";
|
|
43
|
+
} | {
|
|
44
|
+
ask: "hidden-half";
|
|
45
|
+
};
|
|
46
|
+
export type DominoGivens = {
|
|
47
|
+
/** What odd-one-out compares, as the statement names it. */
|
|
48
|
+
property?: "total";
|
|
49
|
+
/** The dots of every tile together, for hidden-half. */
|
|
50
|
+
total?: number;
|
|
51
|
+
/** That the clouds hide the same number of dots, for hidden-half. */
|
|
52
|
+
same?: boolean;
|
|
53
|
+
};
|
|
54
|
+
type DominoOrChoices = DominoScene | ChoicesScene;
|
|
55
|
+
/** dominoSolver reads the dots of domino tiles: the questions of DominoQuestion. */
|
|
56
|
+
export declare const dominoSolver: Solver<DominoOrChoices, DominoQuestion, DominoGivens>;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { plural } from "../kinds/magic-parts.js";
|
|
2
|
+
import { int, isObj, oneOf, only } from "../read.js";
|
|
3
|
+
import { choicesOf } from "./choice-scenes.js";
|
|
4
|
+
import { letters, noScene, solved, unsolved, } from "./proof.js";
|
|
5
|
+
import { askOf, flagOf, sceneless } from "./question.js";
|
|
6
|
+
const members = {
|
|
7
|
+
"most-pips": ["fewest"],
|
|
8
|
+
"odd-one-out": [],
|
|
9
|
+
"chain-half": [],
|
|
10
|
+
"missing-tile": [],
|
|
11
|
+
"hidden-half": [],
|
|
12
|
+
};
|
|
13
|
+
const onChoices = ["most-pips", "odd-one-out"];
|
|
14
|
+
const takes = {
|
|
15
|
+
"odd-one-out": ["property"],
|
|
16
|
+
"hidden-half": ["total", "same"],
|
|
17
|
+
};
|
|
18
|
+
const most = 9;
|
|
19
|
+
const halvesOf = (t) => (Array.isArray(t) ? t : t.halves);
|
|
20
|
+
const isDots = (h) => typeof h === "number";
|
|
21
|
+
/** tileOf is the tile of an option, a domino scene of one tile both of whose halves show dots. */
|
|
22
|
+
function tileOf(o) {
|
|
23
|
+
if (!isObj(o) || o.kind !== "domino")
|
|
24
|
+
return undefined;
|
|
25
|
+
const tiles = o.tiles;
|
|
26
|
+
if (tiles.length !== 1)
|
|
27
|
+
return undefined;
|
|
28
|
+
const t = halvesOf(tiles[0]);
|
|
29
|
+
return t.every(isDots) ? t : undefined;
|
|
30
|
+
}
|
|
31
|
+
const oneTile = "a domino scene of one tile, both halves showing their dots";
|
|
32
|
+
/** offeredTiles reads the tiles of the options a question of tiles answers among, and their paths. */
|
|
33
|
+
function offeredTiles(scene, offered) {
|
|
34
|
+
if (scene?.kind === "choices")
|
|
35
|
+
return { tiles: scene.options.map(tileOf), at: "options" };
|
|
36
|
+
return { tiles: (offered?.choices ?? []).map(tileOf), at: "choices" };
|
|
37
|
+
}
|
|
38
|
+
const totalOf = (t) => t[0] + t[1];
|
|
39
|
+
/** touching lists the pairs of halves that touch, each as [tile, half] places. */
|
|
40
|
+
function touching(scene) {
|
|
41
|
+
const n = scene.tiles.length;
|
|
42
|
+
const out = [];
|
|
43
|
+
for (let i = 0; i + 1 < n; i++)
|
|
44
|
+
out.push([
|
|
45
|
+
[i, 1],
|
|
46
|
+
[i + 1, 0],
|
|
47
|
+
]);
|
|
48
|
+
if (scene.layout === "ring")
|
|
49
|
+
out.push([
|
|
50
|
+
[n - 1, 1],
|
|
51
|
+
[0, 0],
|
|
52
|
+
]);
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
/** odd is the one option whose total differs from the total all the others share. */
|
|
56
|
+
function odd(tiles) {
|
|
57
|
+
const totals = tiles.map(totalOf);
|
|
58
|
+
const odds = totals.flatMap((t, i) => {
|
|
59
|
+
const others = totals.filter((_, j) => j !== i);
|
|
60
|
+
return others.every((u) => u === others[0] && u !== t) ? [i] : [];
|
|
61
|
+
});
|
|
62
|
+
return odds.length === 1 ? odds[0] : undefined;
|
|
63
|
+
}
|
|
64
|
+
function checkGivens(givens, ask, problems) {
|
|
65
|
+
if (givens === undefined) {
|
|
66
|
+
if (ask === "odd-one-out")
|
|
67
|
+
problems.push('givens.property: odd-one-out needs what the statement compares, "total"');
|
|
68
|
+
if (ask === "hidden-half")
|
|
69
|
+
problems.push("givens.total: hidden-half needs the total the statement gives");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!isObj(givens)) {
|
|
73
|
+
problems.push("givens: must be an object");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
only(givens, (ask ? takes[ask] : undefined) ?? [], "givens", problems, `the givens of ${ask ?? "dominoes"}`);
|
|
77
|
+
if (ask === "odd-one-out")
|
|
78
|
+
oneOf(givens.property, ["total"], "givens.property", problems);
|
|
79
|
+
if (ask === "hidden-half") {
|
|
80
|
+
int(givens.total, "givens.total", problems, 0, 100);
|
|
81
|
+
flagOf(givens.same, "givens.same", problems);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** chainProblems lists what keeps a chain's touching halves from matching, but at unknown halves. */
|
|
85
|
+
function chainProblems(scene, ask) {
|
|
86
|
+
if (scene.layout !== "chain" && scene.layout !== "ring")
|
|
87
|
+
return [`question.ask: ${ask} reads a chain or a ring, not a ${scene.layout}`];
|
|
88
|
+
const tiles = scene.tiles;
|
|
89
|
+
return touching(scene).flatMap(([[i, a], [j, b]]) => {
|
|
90
|
+
const x = tiles[i][a];
|
|
91
|
+
const y = tiles[j][b];
|
|
92
|
+
return isDots(x) && isDots(y) && x !== y
|
|
93
|
+
? [`tiles[${i}]: its half ${x} touches ${y} of tiles[${j}]; touching halves match`]
|
|
94
|
+
: [];
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** unknowns lists the places of the halves that show no dots, "?" or "cloud". */
|
|
98
|
+
function unknowns(scene, which) {
|
|
99
|
+
return scene.tiles.flatMap((t, i) => halvesOf(t).flatMap((h, k) => (h === which ? [[i, k]] : [])));
|
|
100
|
+
}
|
|
101
|
+
function check(question, givens, scene, offered) {
|
|
102
|
+
const problems = [];
|
|
103
|
+
const read = askOf(question, members, problems);
|
|
104
|
+
checkGivens(givens, read?.ask, problems);
|
|
105
|
+
if (!read)
|
|
106
|
+
return problems;
|
|
107
|
+
const { q, ask } = read;
|
|
108
|
+
flagOf(q.fewest, "question.fewest", problems);
|
|
109
|
+
const tilesOffered = onChoices.includes(ask);
|
|
110
|
+
if (!scene && !(tilesOffered && (offered?.choices ?? []).length > 0))
|
|
111
|
+
sceneless(ask, tilesOffered
|
|
112
|
+
? "tiles offered as options, a scene of choices or the task's picture options"
|
|
113
|
+
: "a domino scene, a chain or a ring", problems);
|
|
114
|
+
if (problems.length > 0)
|
|
115
|
+
return problems;
|
|
116
|
+
if (tilesOffered) {
|
|
117
|
+
if (scene?.kind === "domino") {
|
|
118
|
+
problems.push(`question.ask: ${ask} reads tiles offered as options, not a domino scene`);
|
|
119
|
+
return problems;
|
|
120
|
+
}
|
|
121
|
+
const { tiles, at } = offeredTiles(scene, offered);
|
|
122
|
+
if (!scene)
|
|
123
|
+
choicesOf(offered, ask, "domino", (o, path) => {
|
|
124
|
+
if (!tileOf(o))
|
|
125
|
+
problems.push(`${path}: must be ${oneTile}`);
|
|
126
|
+
}, problems);
|
|
127
|
+
else {
|
|
128
|
+
if ((offered?.choices ?? []).length > 0)
|
|
129
|
+
problems.push("choices: the scene of choices draws the tiles; offer them once");
|
|
130
|
+
tiles.forEach((t, i) => {
|
|
131
|
+
if (!t)
|
|
132
|
+
problems.push(`${at}[${i}]: must be ${oneTile}`);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (problems.length > 0)
|
|
136
|
+
return problems;
|
|
137
|
+
if (ask === "odd-one-out") {
|
|
138
|
+
if (tiles.length < 3)
|
|
139
|
+
problems.push(`${at}: odd-one-out needs three tiles or more`);
|
|
140
|
+
else if (odd(tiles) === undefined)
|
|
141
|
+
problems.push(`${at}: no one tile has a total of its own while the others share one; the totals are ${tiles.map(totalOf).join(", ")}`);
|
|
142
|
+
}
|
|
143
|
+
return problems;
|
|
144
|
+
}
|
|
145
|
+
if (!scene)
|
|
146
|
+
return problems;
|
|
147
|
+
if (scene.kind === "choices") {
|
|
148
|
+
problems.push(`question.ask: ${ask} reads a domino scene`);
|
|
149
|
+
return problems;
|
|
150
|
+
}
|
|
151
|
+
const asked = unknowns(scene, "?");
|
|
152
|
+
const clouds = unknowns(scene, "cloud");
|
|
153
|
+
if (ask === "chain-half") {
|
|
154
|
+
problems.push(...chainProblems(scene, ask));
|
|
155
|
+
const one = asked.length > 0 ? asked : clouds;
|
|
156
|
+
if (asked.length + clouds.length !== 1)
|
|
157
|
+
problems.push(`tiles: chain-half asks one half, a "?" or a cloud; the ${scene.layout} has ${asked.length} "?" and ${clouds.length} clouds`);
|
|
158
|
+
else {
|
|
159
|
+
const [i, k] = one[0];
|
|
160
|
+
const touched = touching(scene).some(([a, b]) => (a[0] === i && a[1] === k) || (b[0] === i && b[1] === k));
|
|
161
|
+
if (!touched)
|
|
162
|
+
problems.push(`tiles[${i}]: the half asked is an end of the chain and touches none`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (ask === "missing-tile") {
|
|
166
|
+
problems.push(...chainProblems(scene, ask));
|
|
167
|
+
const tiles = choicesOf(offered, ask, "domino", (o, path) => {
|
|
168
|
+
if (!tileOf(o))
|
|
169
|
+
problems.push(`${path}: must be ${oneTile}`);
|
|
170
|
+
}, problems).map(tileOf);
|
|
171
|
+
tiles.forEach((t, j) => {
|
|
172
|
+
const k = tiles.findIndex((u) => t && u && ((u[0] === t[0] && u[1] === t[1]) || (u[0] === t[1] && u[1] === t[0])));
|
|
173
|
+
if (k >= 0 && k < j)
|
|
174
|
+
problems.push(`choices[${j}]: is choices[${k}] or it turned round, the same tile`);
|
|
175
|
+
});
|
|
176
|
+
const gaps = scene.tiles.flatMap((t, i) => (halvesOf(t).every((h) => h === "?") ? [i] : []));
|
|
177
|
+
if (gaps.length !== 1 || asked.length !== 2 || clouds.length > 0)
|
|
178
|
+
problems.push('tiles: missing-tile needs one gap, a tile ["?", "?"], and every other half showing its dots');
|
|
179
|
+
else if (scene.tiles.length < 2)
|
|
180
|
+
problems.push("tiles: the gap needs a tile beside it");
|
|
181
|
+
}
|
|
182
|
+
if (ask === "hidden-half") {
|
|
183
|
+
if (asked.length > 0) {
|
|
184
|
+
const [i] = asked[0];
|
|
185
|
+
problems.push(`tiles[${i}]: shows "?"; hidden-half reads the dots in sight and the clouds`);
|
|
186
|
+
}
|
|
187
|
+
if (clouds.length === 0)
|
|
188
|
+
problems.push("tiles: hidden-half needs a cloud");
|
|
189
|
+
if (clouds.length > 1 && !givens.same)
|
|
190
|
+
problems.push(`givens.same: with ${clouds.length} clouds, hidden-half needs the statement to say they hide the same`);
|
|
191
|
+
}
|
|
192
|
+
return problems;
|
|
193
|
+
}
|
|
194
|
+
function solve(scene, question, givens = {}, offered) {
|
|
195
|
+
if (onChoices.includes(question.ask)) {
|
|
196
|
+
const offers = offeredTiles(scene, offered);
|
|
197
|
+
const tiles = offers.tiles;
|
|
198
|
+
if (tiles.length === 0)
|
|
199
|
+
return noScene;
|
|
200
|
+
const reads = offers.at === "options" ? tiles.map((_, i) => `options[${i}]`) : [];
|
|
201
|
+
if (question.ask === "odd-one-out")
|
|
202
|
+
return solved({ letter: letters[odd(tiles)] }, reads);
|
|
203
|
+
const totals = tiles.map(totalOf);
|
|
204
|
+
const fewest = question.ask === "most-pips" && question.fewest === true;
|
|
205
|
+
const best = fewest ? Math.min(...totals) : Math.max(...totals);
|
|
206
|
+
const at = totals.flatMap((t, i) => (t === best ? [letters[i]] : []));
|
|
207
|
+
if (at.length === 1)
|
|
208
|
+
return solved({ letter: at[0] }, reads);
|
|
209
|
+
return unsolved(`${at.join(" and ")} have ${best} dots each, a tie`, reads);
|
|
210
|
+
}
|
|
211
|
+
if (!scene || scene.kind === "choices")
|
|
212
|
+
return noScene;
|
|
213
|
+
const tiles = scene.tiles.map(halvesOf);
|
|
214
|
+
const reads = tiles.map((_, i) => `tiles[${i}]`);
|
|
215
|
+
switch (question.ask) {
|
|
216
|
+
case "chain-half": {
|
|
217
|
+
const asked = [...unknowns(scene, "?"), ...unknowns(scene, "cloud")][0];
|
|
218
|
+
const pair = touching(scene).find(([a, b]) => (a[0] === asked[0] && a[1] === asked[1]) || (b[0] === asked[0] && b[1] === asked[1]));
|
|
219
|
+
const [i, k] = pair[0][0] === asked[0] && pair[0][1] === asked[1] ? pair[1] : pair[0];
|
|
220
|
+
return solved({ number: tiles[i][k] }, reads);
|
|
221
|
+
}
|
|
222
|
+
case "missing-tile": {
|
|
223
|
+
const gap = tiles.findIndex((t) => t[0] === "?");
|
|
224
|
+
const pairs = touching(scene);
|
|
225
|
+
const left = pairs.find(([, b]) => b[0] === gap)?.[0];
|
|
226
|
+
const right = pairs.find(([a]) => a[0] === gap)?.[1];
|
|
227
|
+
const want = [left, right].map((p) => (p ? tiles[p[0]][p[1]] : undefined));
|
|
228
|
+
const fits = (a, b) => (want[0] === undefined || want[0] === a) && (want[1] === undefined || want[1] === b);
|
|
229
|
+
const at = (offered?.choices ?? []).map(tileOf).flatMap((t, j) => {
|
|
230
|
+
const [a, b] = t;
|
|
231
|
+
return fits(a, b) || fits(b, a) ? [letters[j]] : [];
|
|
232
|
+
});
|
|
233
|
+
if (at.length === 1)
|
|
234
|
+
return solved({ letter: at[0] }, reads);
|
|
235
|
+
return unsolved(at.length === 0 ? "no tile offered fills the gap" : `${at.join(" and ")} both fill the gap`, reads);
|
|
236
|
+
}
|
|
237
|
+
default: {
|
|
238
|
+
const seen = tiles.flat().reduce((s, h) => s + (isDots(h) ? h : 0), 0);
|
|
239
|
+
const clouds = tiles.flat().filter((h) => h === "cloud").length;
|
|
240
|
+
const hidden = givens.total - seen;
|
|
241
|
+
if (hidden < 0)
|
|
242
|
+
return unsolved(`the dots in sight, ${seen}, are more than ${givens.total}`, reads);
|
|
243
|
+
if (hidden % clouds !== 0 || hidden / clouds > most)
|
|
244
|
+
return unsolved(`${hidden} dots do not share into ${plural(clouds, "half", "halves")} of 0 to ${most}`, reads);
|
|
245
|
+
return solved({ number: hidden / clouds }, reads);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** The facts of tiles are each tile that shows dots: of a domino scene, or each option of choices. */
|
|
250
|
+
function facts(scene) {
|
|
251
|
+
if (scene.kind === "choices")
|
|
252
|
+
return scene.options.map((_, i) => `options[${i}]`);
|
|
253
|
+
return scene.tiles.flatMap((t, i) => (halvesOf(t).some(isDots) ? [`tiles[${i}]`] : []));
|
|
254
|
+
}
|
|
255
|
+
/** dominoSolver reads the dots of domino tiles: the questions of DominoQuestion. */
|
|
256
|
+
export const dominoSolver = {
|
|
257
|
+
name: "domino",
|
|
258
|
+
kinds: ["domino", "choices"],
|
|
259
|
+
questions: Object.keys(members),
|
|
260
|
+
check,
|
|
261
|
+
facts,
|
|
262
|
+
solve,
|
|
263
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { GroupsScene } from "../kinds/groups.ts";
|
|
2
|
+
import type { MapScene } from "../kinds/map.ts";
|
|
3
|
+
import { type Thing } from "../things.ts";
|
|
4
|
+
import { type Solver } from "./proof.ts";
|
|
5
|
+
/**
|
|
6
|
+
* A rule of an order of things on a shelf: at and not-at put a thing at an
|
|
7
|
+
* end or in a place counted from the left; next-to and not-next-to, left-of
|
|
8
|
+
* and right-of, place it beside or anywhere left or right of another.
|
|
9
|
+
*/
|
|
10
|
+
export type ShelfRule = {
|
|
11
|
+
who: string;
|
|
12
|
+
is: "at" | "not-at";
|
|
13
|
+
place: number | "left-end" | "right-end";
|
|
14
|
+
} | {
|
|
15
|
+
who: string;
|
|
16
|
+
is: "next-to" | "not-next-to" | "left-of" | "right-of";
|
|
17
|
+
of: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The givens of enumerate, each question's own:
|
|
21
|
+
*
|
|
22
|
+
* - `how-many-pairs`: counts, the number in each of two groups, when the
|
|
23
|
+
* statement tells them and there is no scene; none when the groups are drawn.
|
|
24
|
+
* - `how-many-routes`: from, via and to, the ids of the map's start, stop and
|
|
25
|
+
* end; via may be left out.
|
|
26
|
+
* - `how-many-pairs-within`: count, the number in the group, and eachWay,
|
|
27
|
+
* true when a pair is counted once from each side (a card from A to B and
|
|
28
|
+
* one from B to A).
|
|
29
|
+
* - `which-is-missing`: kinds, the things of each kind a way takes one of.
|
|
30
|
+
* - `how-many-orders`: things, the names of the things to order, and rules.
|
|
31
|
+
*/
|
|
32
|
+
export type EnumerateGivens = {
|
|
33
|
+
counts?: number[];
|
|
34
|
+
from?: string;
|
|
35
|
+
via?: string;
|
|
36
|
+
to?: string;
|
|
37
|
+
count?: number;
|
|
38
|
+
eachWay?: boolean;
|
|
39
|
+
kinds?: Thing[][];
|
|
40
|
+
things?: string[];
|
|
41
|
+
rules?: ShelfRule[];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The questions of how many ways there are, each answered by listing every
|
|
45
|
+
* way:
|
|
46
|
+
*
|
|
47
|
+
* - `how-many-pairs`: the ways to take one thing from each of two groups, a
|
|
48
|
+
* number; it reads the two groups of a scene of groups, each thing once,
|
|
49
|
+
* or givens.counts with no scene.
|
|
50
|
+
* - `how-many-routes`: the ways along the roads of a map from givens.from
|
|
51
|
+
* to givens.to that pass givens.via, none of them through a place twice,
|
|
52
|
+
* an arrow taken only its way, a number. A map joins two places by one
|
|
53
|
+
* road at most, so a parallel road goes through a dot of its own. It reads
|
|
54
|
+
* every place and road.
|
|
55
|
+
* - `how-many-pairs-within`: the pairs a group of givens.count makes, a
|
|
56
|
+
* number; it reads no scene.
|
|
57
|
+
* - `which-is-missing`: the one way of all those that take one thing of
|
|
58
|
+
* each of givens.kinds that no group of the scene shows, each group a way,
|
|
59
|
+
* answered by the letter of the task's picture option that shows it, each
|
|
60
|
+
* a scene of groups of one group, a way.
|
|
61
|
+
* - `how-many-orders`: the orders of givens.things, at most four, that keep
|
|
62
|
+
* every rule, a number; it reads no scene.
|
|
63
|
+
*/
|
|
64
|
+
export type EnumerateQuestion = {
|
|
65
|
+
ask: "how-many-pairs" | "how-many-routes" | "how-many-pairs-within" | "which-is-missing" | "how-many-orders";
|
|
66
|
+
};
|
|
67
|
+
type Scene = GroupsScene | MapScene;
|
|
68
|
+
/**
|
|
69
|
+
* enumerateSolver lists the ways to choose, to go and to order: the
|
|
70
|
+
* questions of EnumerateQuestion. Every way is listed, at most 12 of all
|
|
71
|
+
* that take one thing of each kind and every order of at most four things;
|
|
72
|
+
* a map holds at most 12 places, and every way through them is walked.
|
|
73
|
+
*/
|
|
74
|
+
export declare const enumerateSolver: Solver<Scene, EnumerateQuestion, EnumerateGivens>;
|
|
75
|
+
export {};
|