-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path65472.ts
41 lines (34 loc) · 902 Bytes
/
65472.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
type Source = 6 | 5 | 4 | 7 | 2;
type RedBlock = "🟥";
type BlueBlock = "🟦";
// Repeat `Unit` `Length` times
type Repeat<
Length extends unknown[],
Unit extends string,
Output extends string = ""
> = Length extends [number, ...infer Rest]
? Repeat<Rest, Unit, `${Output}${Unit}`>
: Output;
// Generate tuple from input
type Tuple<
Length extends number,
Output extends unknown[] = []
> = Output["length"] extends Length
? Output
: Tuple<Length, [114514, ...Output]>;
type IsEven<Input extends unknown[]> = Input extends [
unknown,
unknown,
...infer Rest
]
? Rest extends []
? true
: IsEven<Rest>
: false;
type Process<Input extends number> = {
[key in Input]: IsEven<Tuple<key>> extends true
? Repeat<Tuple<key>, RedBlock>
: Repeat<Tuple<key>, BlueBlock>;
};
// use an IDE or ts playground and hover to see 65472
type Result = Process<Source>;