-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
- Loading branch information
1 parent
e448fbd
commit d14adf9
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>; |