Skip to content

Commit

Permalink
feat: solved day 16 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 e448fbd commit d14adf9
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions advent-of-typescript/2023/day_16.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Equal, Expect } from "type-testing";

import { Increment } from "@/utils/type-helpers";

/* -----------------------------------------------------------------------------------------------
* Code here
* -----------------------------------------------------------------------------------------------*/

/// From 2023, Day 12
type FindSantaInRow<T, I extends string[] = []> = T extends [
infer First,
...infer Rest,
]
? First extends "🎅🏼"
? I["length"]
: FindSantaInRow<Rest, Increment<I>>
: never;

type FindSanta<T, Col extends string[] = []> = T extends [
infer Row,
...infer Rest,
]
? Row extends string[]
? FindSantaInRow<Row> extends never
? Rest extends string[][]
? FindSanta<Rest, Increment<Col>>
: never
: [Col["length"], FindSantaInRow<Row>]
: never
: never;

/* -----------------------------------------------------------------------------------------------
* Do not edit below this line
* -----------------------------------------------------------------------------------------------*/

type Forest0 = [
["🎅🏼", "🎄", "🎄", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
];
type test_0_actual = FindSanta<Forest0>;
// ^?
type test_0_expected = [0, 0];
type test_0 = Expect<Equal<test_0_expected, test_0_actual>>;

type Forest1 = [
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎅🏼", "🎄", "🎄"],
];
type test_1_actual = FindSanta<Forest1>;
// ^?
type test_1_expected = [3, 1];
type test_1 = Expect<Equal<test_1_expected, test_1_actual>>;

type Forest2 = [
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎄", "🎅🏼", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
];
type test_2_actual = FindSanta<Forest2>;
// ^?
type test_2_expected = [2, 2];
type test_2 = Expect<Equal<test_2_expected, test_2_actual>>;

type Forest3 = [
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎅🏼", "🎄", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
];
type test_3_actual = FindSanta<Forest3>;
// ^?
type test_3_expected = [2, 1];
type test_3 = Expect<Equal<test_3_expected, test_3_actual>>;

type Forest4 = [
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎄", "🎅🏼", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
["🎄", "🎄", "🎄", "🎄"],
];
type test_4_actual = FindSanta<Forest4>;
// ^?
type test_4_expected = [1, 2];
type test_4 = Expect<Equal<test_4_expected, test_4_actual>>;

0 comments on commit d14adf9

Please sign in to comment.