From 46779a7da5198db0ca4ecc2f58b7c48ae474465a Mon Sep 17 00:00:00 2001 From: Vasily Guzov Date: Sun, 27 Oct 2024 23:55:17 +0300 Subject: [PATCH] [ya-day1] tshortChooser solution for base case --- lib/tiShortChoser/tiShortChoser.test.ts | 27 ++++++++++++++++++++++++- lib/tiShortChoser/tiShortChoser.ts | 11 +++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/tiShortChoser/tiShortChoser.test.ts b/lib/tiShortChoser/tiShortChoser.test.ts index 00439c3..10b8f73 100644 --- a/lib/tiShortChoser/tiShortChoser.test.ts +++ b/lib/tiShortChoser/tiShortChoser.test.ts @@ -3,6 +3,31 @@ import { tiShortChoser } from "./tiShortChoser.ts"; describe("tiShortChoser", () => { it("tiShortChoser 6, 2, 7, 3", () => { - expect(tiShortChoser(6, 2, 7, 3)).toEqual([3, 4]); + expect(tiShortChoser(6, 2, 7, 3)).toEqual("3 4"); + }); + + it("tiShortChoser 6, 6, 7, 3", () => { + expect(tiShortChoser(6, 6, 7, 3)).toEqual("2 4"); + }); + + it("tiShortChoser 3, 3, 5, 5", () => { + expect(tiShortChoser(3, 3, 5, 5)).toEqual("2 2"); + }); + + it("tiShortChoser 1, 1, 99, 99", () => { + expect(tiShortChoser(1, 1, 99, 99)).toEqual("2 2"); + }); + + it("tiShortChoser 5, 7, 7, 3", () => { + expect(tiShortChoser(5, 7, 3, 2)).toEqual("6 3"); + }); + it("tiShortChoser 5, 7, 7, 3", () => { + expect(tiShortChoser(5, 7, 3, 2)).toEqual("6 3"); + }); + it("tiShortChoser 5, 0, 7, 3", () => { + expect(tiShortChoser(5, 0, 7, 3)).toEqual("1 4"); + }); + it("tiShortChoser 0, 1, 7, 3", () => { + expect(tiShortChoser(0, 1, 17, 50)).toEqual("1 18"); }); }); diff --git a/lib/tiShortChoser/tiShortChoser.ts b/lib/tiShortChoser/tiShortChoser.ts index a3e0b04..21f6b99 100644 --- a/lib/tiShortChoser/tiShortChoser.ts +++ b/lib/tiShortChoser/tiShortChoser.ts @@ -4,5 +4,14 @@ export function tiShortChoser( sBlue: number, sRed: number, ) { - return [3, 4]; + let tishort = tBlue > tRed ? tRed + 1 : tBlue + 1; + let socks = sBlue > sRed ? sRed + 1 : sBlue + 1; + + if (tBlue === tRed) tishort = tRed + 1; + if (sBlue === sRed) socks = sRed + 1; + + if (tBlue === tRed && tBlue === 1) tishort = 2; + if (sBlue === sRed && sBlue === 1) socks = 2; + + return [tishort, socks].join(" "); }