diff --git a/advent-of-typescript/2023/day_16.ts b/advent-of-typescript/2023/day_16.ts new file mode 100644 index 0000000..4c904e0 --- /dev/null +++ b/advent-of-typescript/2023/day_16.ts @@ -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 extends [ + infer First, + ...infer Rest, +] + ? First extends "🎅🏼" + ? I["length"] + : FindSantaInRow> + : never; + +type FindSanta = T extends [ + infer Row, + ...infer Rest, +] + ? Row extends string[] + ? FindSantaInRow extends never + ? Rest extends string[][] + ? FindSanta> + : never + : [Col["length"], FindSantaInRow] + : never + : never; + +/* ----------------------------------------------------------------------------------------------- + * Do not edit below this line + * -----------------------------------------------------------------------------------------------*/ + +type Forest0 = [ + ["🎅🏼", "🎄", "🎄", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], +]; +type test_0_actual = FindSanta; +// ^? +type test_0_expected = [0, 0]; +type test_0 = Expect>; + +type Forest1 = [ + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎅🏼", "🎄", "🎄"], +]; +type test_1_actual = FindSanta; +// ^? +type test_1_expected = [3, 1]; +type test_1 = Expect>; + +type Forest2 = [ + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎄", "🎅🏼", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], +]; +type test_2_actual = FindSanta; +// ^? +type test_2_expected = [2, 2]; +type test_2 = Expect>; + +type Forest3 = [ + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎅🏼", "🎄", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], +]; +type test_3_actual = FindSanta; +// ^? +type test_3_expected = [2, 1]; +type test_3 = Expect>; + +type Forest4 = [ + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎄", "🎅🏼", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], + ["🎄", "🎄", "🎄", "🎄"], +]; +type test_4_actual = FindSanta; +// ^? +type test_4_expected = [1, 2]; +type test_4 = Expect>;