Skip to content

Commit

Permalink
feat: solved day 15 type challenge
Browse files Browse the repository at this point in the history
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
  • Loading branch information
rajput-hemant committed Dec 16, 2023
1 parent d14adf9 commit dd0493d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions advent-of-typescript/2023/day_15.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Equal, Expect } from "type-testing";

/* -----------------------------------------------------------------------------------------------
* Code Here
* -----------------------------------------------------------------------------------------------*/

type BoxToys<S, N, Arr extends S[] = []> =
// Arr["length"] extends N // this doesn't work w/ union types
N extends Arr["length"] // works
? Arr
: BoxToys<S, N, [...Arr, S]>;

/* -----------------------------------------------------------------------------------------------
* Do Not Edit Below This Line
* -----------------------------------------------------------------------------------------------*/

type test_doll_actual = BoxToys<"doll", 1>;
// ^?
type test_doll_expected = ["doll"];
type test_doll = Expect<Equal<test_doll_expected, test_doll_actual>>;

type test_nutcracker_actual = BoxToys<"nutcracker", 3 | 4>;
// ^?
type test_nutcracker_expected =
| ["nutcracker", "nutcracker", "nutcracker"]
| ["nutcracker", "nutcracker", "nutcracker", "nutcracker"];
type test_nutcracker = Expect<
Equal<test_nutcracker_expected, test_nutcracker_actual>
>;

0 comments on commit dd0493d

Please sign in to comment.