Skip to content

Commit

Permalink
add day 18
Browse files Browse the repository at this point in the history
  • Loading branch information
zyhou committed Dec 18, 2023
1 parent 57a305f commit 4ec6e46
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions 18/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Expect, Equal } from "type-testing";

type Count<
Toys extends string[],
Toy extends string,
Counts extends string[] = [],
> = Toys extends [infer First, ...infer Rest extends string[]]
? First extends Toy
? Count<Rest, Toy, [...Counts, "1"]>
: Count<Rest, Toy, Counts>
: Counts["length"];

// ------------------- Test section ---------------------

// prettier-ignore
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 4ec6e46

Please sign in to comment.