Skip to content

Commit 1df1a2f

Browse files
committed
Day 15.
1 parent 73a6af0 commit 1df1a2f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

2024/day-15.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,24 @@ import { Expect, Equal } from "../test";
2525
*/
2626
type GetRoute<Str extends string> = BuildRoute<Trim<Str>>;
2727

28-
type BuildRoute<Str extends string, DashCount extends number[] = []> = Str extends `-${infer RestStr}`
29-
? BuildRoute<RestStr, [...DashCount, 0]>
30-
: Str extends `${infer Destination}-${infer RestStr}`
31-
? [[Destination, DashCount["length"]], ...BuildRoute<RestStr, [0]>]
32-
: Str extends ""
33-
? []
34-
: [[Str, DashCount["length"]]];
35-
36-
type Trim<Str extends string> = Str extends `-${infer RestStr}` ? Trim<RestStr> : Str;
28+
// prettier-ignore
29+
type BuildRoute<
30+
Str extends string,
31+
DashCount extends number[] = [],
32+
> = Str extends `-${infer RestStr}`
33+
? BuildRoute<RestStr, [...DashCount, 0]>
34+
: Str extends `${infer Destination}-${infer RestStr}`
35+
? [[Destination, DashCount["length"]], ...BuildRoute<RestStr, [0]>]
36+
: Str extends ""
37+
? []
38+
: [[Str, DashCount["length"]]];
39+
40+
// prettier-ignore
41+
type Trim<Str extends string> = Str extends `-${infer RestStr}`
42+
? Trim<RestStr>
43+
: Str extends `${infer RestStr}-`
44+
? Trim<RestStr>
45+
: Str;
3746

3847
// *************************************************************************************
3948
// *** Tests ***

0 commit comments

Comments
 (0)