From 9f0014ee994116277d3ac5ca507c03b42f922bd1 Mon Sep 17 00:00:00 2001 From: BlueRexPY Date: Tue, 26 Dec 2023 01:04:49 +0100 Subject: [PATCH] added day 18 --- .vscode/settings.json | 1 + Day18/description.md | 14 +++++ Day18/solution.ts | 11 ++++ Day18/test.ts | 125 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+) create mode 100644 Day18/description.md create mode 100644 Day18/solution.ts create mode 100644 Day18/test.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 9afd058..06a403c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "aadamw", "Allis", "anthonyshew", + "arguemnt", "ayrock", "ayush", "basokant", diff --git a/Day18/description.md b/Day18/description.md new file mode 100644 index 0000000..06f8047 --- /dev/null +++ b/Day18/description.md @@ -0,0 +1,14 @@ +# Santa's Remaining Deliveries + +Santa needs your help to count the number of presents he has to deliver! He's got all kinds of presents, from video game consoles (๐ŸŽฎ), stuffed animals (๐Ÿงธ), toy cars (๐ŸŽ๏ธ), books (๐Ÿ“š), and more! + +We need a general purpose type that can take a tuple of items as its first arguemnt and an item to search for as the second argument. It should return a count of the item specified. + +For example: + +```ts +Count<["๐Ÿ‘Ÿ", "๐Ÿ‘Ÿ", "๐Ÿ’ป", "๐ŸŽธ", "๐Ÿงฉ", "๐Ÿ‘Ÿ", "๐Ÿงธ"], "๐Ÿ‘Ÿ">; +``` + +should return `3` because there are three `๐Ÿ‘Ÿ`. +prompt by [Dimitri Mitropoulos](https://github.com/dimitropoulos) of [MiTS](https://www.youtube.com/@MichiganTypeScript) diff --git a/Day18/solution.ts b/Day18/solution.ts new file mode 100644 index 0000000..3a881ea --- /dev/null +++ b/Day18/solution.ts @@ -0,0 +1,11 @@ +type Count< + List extends any[], + Target extends string, + Accumulator extends any[] = [] +> = List extends [infer Current, ...infer Rest] + ? Current extends Target + ? Count + : Count + : Accumulator["length"]; + +export { Count }; diff --git a/Day18/test.ts b/Day18/test.ts new file mode 100644 index 0000000..65607df --- /dev/null +++ b/Day18/test.ts @@ -0,0 +1,125 @@ +import { Expect, Equal } from "type-testing"; +import { Count } from "./solution"; + +type ToySack = [ + "๐ŸŽธ", + "๐ŸŽง", + "๐Ÿ‘Ÿ", + "๐Ÿ‘Ÿ", + "๐Ÿ’ป", + "๐Ÿช€", + "๐Ÿงฉ", + "๐ŸŽฎ", + "๐ŸŽจ", + "๐Ÿ•น๏ธ", + "๐Ÿ“ฑ", + "๐Ÿงฉ", + "๐Ÿงธ", + "๐ŸŽง", + "๐Ÿ‘Ÿ", + "๐Ÿšฒ", + "๐Ÿ“š", + "โŒš", + "๐ŸŽจ", + "๐Ÿ‘Ÿ", + "๐ŸŽธ", + "๐Ÿงธ", + "๐Ÿ‘Ÿ", + "๐ŸŽธ", + "๐Ÿ“ฑ", + "๐ŸŽง", + "๐ŸŽฎ", + "๐ŸŽ’", + "๐Ÿ“ฑ", + "๐Ÿงฉ", + "๐Ÿงฉ", + "๐Ÿšฒ", + "๐Ÿ•น๏ธ", + "๐Ÿงต", + "๐Ÿ“ฑ", + "๐Ÿ•น๏ธ", + "๐Ÿ•ฐ๏ธ", + "๐Ÿงข", + "๐Ÿ•น๏ธ", + "๐Ÿ‘Ÿ", + "๐Ÿงธ", + "๐Ÿ“š", + "๐Ÿง", + "๐Ÿงฉ", + "๐ŸŽธ", + "๐ŸŽฎ", + "๐Ÿง", + "๐Ÿ“š", + "๐Ÿ’ป", + "โŒš", + "๐Ÿ›น", + "๐Ÿง", + "๐Ÿงฃ", + "๐Ÿช", + "๐ŸŽธ", + "๐Ÿงธ", + "๐Ÿงธ", + "๐Ÿงธ", + "๐Ÿงฉ", + "๐Ÿช", + "๐ŸŽ๏ธ", + "๐ŸŽ๏ธ", + "๐Ÿง", + "๐Ÿ“š", + "๐Ÿงธ", + "๐Ÿ•ถ๏ธ", + "๐Ÿ’ป", + "โŒš", + "โŒš", + "๐Ÿ•ถ๏ธ", + "๐ŸŽง", + "๐ŸŽง", + "๐ŸŽง", + "๐Ÿ’ป", + "๐Ÿ‘Ÿ", + "๐ŸŽธ", + "๐Ÿ’ป", + "๐Ÿช", + "๐Ÿ“š", + "๐ŸŽจ", + "๐Ÿ“ฑ", + "๐ŸŽง", + "๐Ÿ“ฑ", + "๐ŸŽธ", + "๐ŸŽ๏ธ", + "๐Ÿ‘Ÿ", + "๐Ÿšฒ", + "๐Ÿ“ฑ", + "๐Ÿšฒ", + "๐ŸŽธ" +]; + +type test_0_actual = Count; +// ^? +type test_0_expected = 8; +type test_0 = Expect>; + +type test_1_actual = Count; +// ^? +type test_1_expected = 0; +type test_1 = Expect>; + +type test_2_actual = Count; +// ^? +type test_2_expected = 6; +type test_2 = Expect>; + +type test_3_actual = Count; +// ^? +type test_3_expected = 1; +type test_3 = Expect>; + +type test_4_actual = Count; +// ^? +type test_4_expected = 3; +type test_4 = Expect>; + +type test_5_actual = Count; +// ^? +type test_5_expected = 5; +type test_5 = Expect>;