Skip to content

Commit

Permalink
added day 18
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueRexPY committed Dec 26, 2023
1 parent 624c781 commit 9f0014e
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"aadamw",
"Allis",
"anthonyshew",
"arguemnt",
"ayrock",
"ayush",
"basokant",
Expand Down
14 changes: 14 additions & 0 deletions Day18/description.md
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions Day18/solution.ts
Original file line number Diff line number Diff line change
@@ -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<Rest, Target, [...Accumulator, Current]>
: Count<Rest, Target, [...Accumulator]>
: Accumulator["length"];

export { Count };
125 changes: 125 additions & 0 deletions Day18/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { Expect, Equal } from "type-testing";
import { Count } from "./solution";

type ToySack = [
"๐ŸŽธ",
"๐ŸŽง",
"๐Ÿ‘Ÿ",
"๐Ÿ‘Ÿ",
"๐Ÿ’ป",
"๐Ÿช€",
"๐Ÿงฉ",
"๐ŸŽฎ",
"๐ŸŽจ",
"๐Ÿ•น๏ธ",
"๐Ÿ“ฑ",
"๐Ÿงฉ",
"๐Ÿงธ",
"๐ŸŽง",
"๐Ÿ‘Ÿ",
"๐Ÿšฒ",
"๐Ÿ“š",
"โŒš",
"๐ŸŽจ",
"๐Ÿ‘Ÿ",
"๐ŸŽธ",
"๐Ÿงธ",
"๐Ÿ‘Ÿ",
"๐ŸŽธ",
"๐Ÿ“ฑ",
"๐ŸŽง",
"๐ŸŽฎ",
"๐ŸŽ’",
"๐Ÿ“ฑ",
"๐Ÿงฉ",
"๐Ÿงฉ",
"๐Ÿšฒ",
"๐Ÿ•น๏ธ",
"๐Ÿงต",
"๐Ÿ“ฑ",
"๐Ÿ•น๏ธ",
"๐Ÿ•ฐ๏ธ",
"๐Ÿงข",
"๐Ÿ•น๏ธ",
"๐Ÿ‘Ÿ",
"๐Ÿงธ",
"๐Ÿ“š",
"๐Ÿง",
"๐Ÿงฉ",
"๐ŸŽธ",
"๐ŸŽฎ",
"๐Ÿง",
"๐Ÿ“š",
"๐Ÿ’ป",
"โŒš",
"๐Ÿ›น",
"๐Ÿง",
"๐Ÿงฃ",
"๐Ÿช",
"๐ŸŽธ",
"๐Ÿงธ",
"๐Ÿงธ",
"๐Ÿงธ",
"๐Ÿงฉ",
"๐Ÿช",
"๐ŸŽ๏ธ",
"๐ŸŽ๏ธ",
"๐Ÿง",
"๐Ÿ“š",
"๐Ÿงธ",
"๐Ÿ•ถ๏ธ",
"๐Ÿ’ป",
"โŒš",
"โŒš",
"๐Ÿ•ถ๏ธ",
"๐ŸŽง",
"๐ŸŽง",
"๐ŸŽง",
"๐Ÿ’ป",
"๐Ÿ‘Ÿ",
"๐ŸŽธ",
"๐Ÿ’ป",
"๐Ÿช",
"๐Ÿ“š",
"๐ŸŽจ",
"๐Ÿ“ฑ",
"๐ŸŽง",
"๐Ÿ“ฑ",
"๐ŸŽธ",
"๐ŸŽ๏ธ",
"๐Ÿ‘Ÿ",
"๐Ÿšฒ",
"๐Ÿ“ฑ",
"๐Ÿšฒ",
"๐ŸŽธ"
];

type test_0_actual = Count<ToySack, "๐Ÿ‘Ÿ">;
// ^?
type test_0_expected = 8;
type test_0 = Expect<Equal<test_0_expected, test_0_actual>>;

type test_1_actual = Count<ToySack, "๐Ÿงฆ">;
// ^?
type test_1_expected = 0;
type test_1 = Expect<Equal<test_1_expected, test_1_actual>>;

type test_2_actual = Count<ToySack, "๐Ÿงฉ">;
// ^?
type test_2_expected = 6;
type test_2 = Expect<Equal<test_2_expected, test_2_actual>>;

type test_3_actual = Count<ToySack, "๐Ÿ›น">;
// ^?
type test_3_expected = 1;
type test_3 = Expect<Equal<test_3_expected, test_3_actual>>;

type test_4_actual = Count<ToySack, "๐ŸŽ๏ธ">;
// ^?
type test_4_expected = 3;
type test_4 = Expect<Equal<test_4_expected, test_4_actual>>;

type test_5_actual = Count<ToySack, "๐Ÿ“š">;
// ^?
type test_5_expected = 5;
type test_5 = Expect<Equal<test_5_expected, test_5_actual>>;

0 comments on commit 9f0014e

Please sign in to comment.