From d6ece9360b72552f979ca9d59766c7a11ac60fd8 Mon Sep 17 00:00:00 2001 From: Vasily Guzov Date: Sat, 2 Nov 2024 01:54:27 +0300 Subject: [PATCH] [ya-day1] tshortChooser teste 1 - 19 --- lib/tiShortChoser/tiShortChoser.test.ts | 78 ++++++++++++++++++++----- lib/tiShortChoser/tiShortChoser.ts | 48 +++++++++++---- 2 files changed, 101 insertions(+), 25 deletions(-) diff --git a/lib/tiShortChoser/tiShortChoser.test.ts b/lib/tiShortChoser/tiShortChoser.test.ts index 10b8f73..4a8e5e9 100644 --- a/lib/tiShortChoser/tiShortChoser.test.ts +++ b/lib/tiShortChoser/tiShortChoser.test.ts @@ -2,32 +2,80 @@ import { describe, it, expect } from "vitest"; import { tiShortChoser } from "./tiShortChoser.ts"; describe("tiShortChoser", () => { - it("tiShortChoser 6, 2, 7, 3", () => { + it("N1 | 6, 2, 7, 3", () => { 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("N2 | 1, 1, 1, 1", () => { + expect(tiShortChoser(1, 1, 1, 1)).toEqual("2 1"); }); - it("tiShortChoser 3, 3, 5, 5", () => { - expect(tiShortChoser(3, 3, 5, 5)).toEqual("2 2"); + it("N3 | 10, 10, 10, 10", () => { + expect(tiShortChoser(10, 10, 10, 10)).toEqual("11 1"); + }); + it("N4 0, 2, 5, 1", () => { + expect(tiShortChoser(0, 2, 5, 1)).toEqual("1 6"); + }); + it("N5 9, 0, 5, 2", () => { + expect(tiShortChoser(9, 0, 5, 2)).toEqual("1 3"); + }); + it("N6 | 10, 7, 0, 4", () => { + expect(tiShortChoser(10, 7, 0, 4)).toEqual("11 1"); + }); + it("N6.1 | 7, 10, 0, 4", () => { + expect(tiShortChoser(7, 10, 0, 4)).toEqual("8 1"); }); - it("tiShortChoser 1, 1, 99, 99", () => { - expect(tiShortChoser(1, 1, 99, 99)).toEqual("2 2"); + it("N7 | 0, 1, 1, 1", () => { + expect(tiShortChoser(0, 1, 1, 1)).toEqual("1 2"); }); - it("tiShortChoser 5, 7, 7, 3", () => { - expect(tiShortChoser(5, 7, 3, 2)).toEqual("6 3"); + it("tiShortChoser 1, 0, 1, 1", () => { + expect(tiShortChoser(1, 0, 1, 1)).toEqual("1 2"); + }); + it("tiShortChoser 1, 1, 0, 1", () => { + expect(tiShortChoser(1, 1, 0, 1)).toEqual("2 1"); }); - it("tiShortChoser 5, 7, 7, 3", () => { - expect(tiShortChoser(5, 7, 3, 2)).toEqual("6 3"); + it("tiShortChoser 1, 1, 1, 0", () => { + expect(tiShortChoser(1, 1, 1, 0)).toEqual("2 1"); }); - it("tiShortChoser 5, 0, 7, 3", () => { - expect(tiShortChoser(5, 0, 7, 3)).toEqual("1 4"); + it("tiShortChoser 0, 1, 0, 1", () => { + expect(tiShortChoser(0, 1, 0, 1)).toEqual("1 1"); }); - it("tiShortChoser 0, 1, 7, 3", () => { - expect(tiShortChoser(0, 1, 17, 50)).toEqual("1 18"); + it("tiShortChoser 6, 1, 8, 4", () => { + expect(tiShortChoser(6, 1, 8, 4)).toEqual("2 5"); }); + it("tiShortChoser 0, 8, 0, 8", () => { + expect(tiShortChoser(0, 8, 0, 8)).toEqual("1 1"); + }); + it("tiShortChoser 1, 1, 4, 6", () => { + expect(tiShortChoser(1, 1, 4, 6)).toEqual("2 1"); + }); + // 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"); + // }); + // it("tiShortChoser 1000, 1, 1, 1000 ", () => { + // expect(tiShortChoser(1000, 1, 1, 1000)).toEqual("1 18"); + // }); + // it("tiShortChoser 1000, 1, 1000, 1 ", () => { + // expect(tiShortChoser(1000, 1, 1000, 1)).toEqual("1 18"); + // }); }); + + +// 0 1 0 1 | 1 1 +// 0 8 0 8 | 1 1 +// 1 1 4 6 | 2 1 +// 10, 10, 10, 10 +// -------------- +// +// 4 4 4 6 | 5 1 +// 8 9 5 9 | 10 1 +// 1000 1 1000 1 | 2 1 +// 1000 1 1 1000 | 1001 1 diff --git a/lib/tiShortChoser/tiShortChoser.ts b/lib/tiShortChoser/tiShortChoser.ts index 21f6b99..5721ea8 100644 --- a/lib/tiShortChoser/tiShortChoser.ts +++ b/lib/tiShortChoser/tiShortChoser.ts @@ -1,17 +1,45 @@ export function tiShortChoser( - tBlue: number, - tRed: number, - sBlue: number, - sRed: number, + tB: number, + tR: number, + sB: number, + sR: number, ) { - let tishort = tBlue > tRed ? tRed + 1 : tBlue + 1; - let socks = sBlue > sRed ? sRed + 1 : sBlue + 1; + let tishort = 0; + let socks = 0; + const blueIsGrater = tB + sB > tR + sR; + const isEquaal = tB + sB === tR + sR; + const tIsEquale = tB === tR && tB > 0; + const sIsEquale = sB === sR && sB > 0; - if (tBlue === tRed) tishort = tRed + 1; - if (sBlue === sRed) socks = sRed + 1; + if (blueIsGrater) { + tishort = tR + 1; + socks = sR + 1; + } else { + tishort = tB + 1; + socks = sB + 1; + } + + if (tIsEquale || isEquaal) { + tishort = tB + 1; + socks = 1; + } + + if (sIsEquale && !isEquaal) { + tishort = 1; + socks = sB + 1; + } + + if (tB === 0 || tR === 0) { + tishort = 1; + socks = tB === 0 ? sB + 1 : sR + 1; + } + + if (sB === 0 || sR === 0) { + socks = 1; + tishort = sB === 0 ? tB + 1 : tR + 1; + } - if (tBlue === tRed && tBlue === 1) tishort = 2; - if (sBlue === sRed && sBlue === 1) socks = 2; return [tishort, socks].join(" "); } +