-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22.ts
90 lines (75 loc) · 2.08 KB
/
22.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/** because "dashing" implies speed */
type Dasher = "💨";
/** representing dancing or grace */
type Dancer = "💃";
/** a deer, prancing */
type Prancer = "🦌";
/** a star for the dazzling, slightly mischievous Vixen */
type Vixen = "🌟";
/** for the celestial body that shares its name */
type Comet = "☄️";
/** symbolizing love, as Cupid is the god of love */
type Cupid = "❤️";
/** representing thunder, as "Donner" means thunder in German */
type Donner = "🌩️";
/** meaning lightning in German, hence the lightning bolt */
type Blitzen = "⚡";
/** for his famous red nose */
type Rudolph = "🔴";
type Reindeer =
| Dasher
| Dancer
| Prancer
| Vixen
| Comet
| Cupid
| Donner
| Blitzen
| Rudolph;
type Tuple<
TSize extends number,
TItem,
TResult extends Array<TItem> = []
> = TSize extends TResult["length"]
? TResult
: Tuple<TSize, TItem, [...TResult, TItem]>;
type GridRow = Tuple<3, Reindeer>;
type Grid = Tuple<3, GridRow>;
type Game = Tuple<9, Grid>;
type GridRepeat<TGame extends Array<Grid>> = TGame extends [
...infer TFirst extends Grid,
...infer TRest extends Array<Grid>
]
? Reindeer extends TFirst[number][number]
? GridRepeat<TRest>
: true
: false;
type RowRepeat<TGame extends Array<Grid>> = TGame extends [
infer TFirst extends Grid,
infer TSecond extends Grid,
infer TThird extends Grid,
...infer TRest extends Grid[]
]
? [Reindeer, Reindeer, Reindeer] extends [
TFirst[0][number] | TSecond[0][number] | TThird[0][number],
TFirst[1][number] | TSecond[1][number] | TThird[1][number],
TFirst[2][number] | TSecond[2][number] | TThird[2][number]
]
? RowRepeat<TRest>
: true
: false;
type ColumnRepeat<
TGame extends Array<Grid>,
TCount extends Array<1> = []
> = TCount["length"] extends 3
? false
: Reindeer extends TGame[number][number][TCount["length"]]
? ColumnRepeat<TGame, [...TCount, 1]>
: true;
type Validate<TGame extends Game> = true extends [
GridRepeat<TGame>,
RowRepeat<TGame>,
ColumnRepeat<TGame>
][number]
? false
: true;