diff --git a/advent-of-typescript/2023/day_17.ts b/advent-of-typescript/2023/day_17.ts new file mode 100644 index 0000000..6286f13 --- /dev/null +++ b/advent-of-typescript/2023/day_17.ts @@ -0,0 +1,75 @@ +import { Equal, Expect } from "type-testing"; + +/* ----------------------------------------------------------------------------------------------- + * Code here + * -----------------------------------------------------------------------------------------------*/ + +type RockPaperScissors = "👊🏻" | "🖐🏾" | "✌🏽"; + +type WhoWins< + O extends RockPaperScissors, + M extends RockPaperScissors, +> = O extends M + ? "draw" + : M extends "🖐🏾" + ? O extends "👊🏻" + ? "win" + : "lose" + : M extends "👊🏻" + ? O extends "✌🏽" + ? "win" + : "lose" + : M extends "✌🏽" + ? O extends "🖐🏾" + ? "win" + : "lose" + : never; + +/* ----------------------------------------------------------------------------------------------- + * Do not edit below this line + * -----------------------------------------------------------------------------------------------*/ + +type test_0_actual = WhoWins<"👊🏻", "🖐🏾">; +// ^? +type test_0_expected = "win"; +type test_0 = Expect>; + +type test_1_actual = WhoWins<"👊🏻", "✌🏽">; +// ^? +type test_1_expected = "lose"; +type test_1 = Expect>; + +type test_2_actual = WhoWins<"👊🏻", "👊🏻">; +// ^? +type test_2_expected = "draw"; +type test_2 = Expect>; + +type test_3_actual = WhoWins<"🖐🏾", "👊🏻">; +// ^? +type test_3_expected = "lose"; +type test_3 = Expect>; + +type test_4_actual = WhoWins<"🖐🏾", "✌🏽">; +// ^? +type test_4_expected = "win"; +type test_4 = Expect>; + +type test_5_actual = WhoWins<"🖐🏾", "🖐🏾">; +// ^? +type test_5_expected = "draw"; +type test_5 = Expect>; + +type test_6_actual = WhoWins<"✌🏽", "👊🏻">; +// ^? +type test_6_expected = "win"; +type test_6 = Expect>; + +type test_7_actual = WhoWins<"✌🏽", "✌🏽">; +// ^? +type test_7_expected = "draw"; +type test_7 = Expect>; + +type test_8_actual = WhoWins<"✌🏽", "🖐🏾">; +// ^? +type test_8_expected = "lose"; +type test_8 = Expect>;