[ya-day1] tshortChooser teste 1 - 19

main
Vasily Guzov 1 year ago
parent 46779a7da5
commit d6ece9360b

@ -2,32 +2,80 @@ import { describe, it, expect } from "vitest";
import { tiShortChoser } from "./tiShortChoser.ts"; import { tiShortChoser } from "./tiShortChoser.ts";
describe("tiShortChoser", () => { describe("tiShortChoser", () => {
it("tiShortChoser 6, 2, 7, 3", () => { it("N1 | 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", () => { it("N2 | 1, 1, 1, 1", () => {
expect(tiShortChoser(6, 6, 7, 3)).toEqual("2 4"); expect(tiShortChoser(1, 1, 1, 1)).toEqual("2 1");
}); });
it("tiShortChoser 3, 3, 5, 5", () => { it("N3 | 10, 10, 10, 10", () => {
expect(tiShortChoser(3, 3, 5, 5)).toEqual("2 2"); 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", () => { it("N7 | 0, 1, 1, 1", () => {
expect(tiShortChoser(1, 1, 99, 99)).toEqual("2 2"); expect(tiShortChoser(0, 1, 1, 1)).toEqual("1 2");
}); });
it("tiShortChoser 5, 7, 7, 3", () => { it("tiShortChoser 1, 0, 1, 1", () => {
expect(tiShortChoser(5, 7, 3, 2)).toEqual("6 3"); 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", () => { it("tiShortChoser 1, 1, 1, 0", () => {
expect(tiShortChoser(5, 7, 3, 2)).toEqual("6 3"); expect(tiShortChoser(1, 1, 1, 0)).toEqual("2 1");
}); });
it("tiShortChoser 5, 0, 7, 3", () => { it("tiShortChoser 0, 1, 0, 1", () => {
expect(tiShortChoser(5, 0, 7, 3)).toEqual("1 4"); expect(tiShortChoser(0, 1, 0, 1)).toEqual("1 1");
}); });
it("tiShortChoser 0, 1, 7, 3", () => { it("tiShortChoser 6, 1, 8, 4", () => {
expect(tiShortChoser(0, 1, 17, 50)).toEqual("1 18"); 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

@ -1,17 +1,45 @@
export function tiShortChoser( export function tiShortChoser(
tBlue: number, tB: number,
tRed: number, tR: number,
sBlue: number, sB: number,
sRed: number, sR: number,
) { ) {
let tishort = tBlue > tRed ? tRed + 1 : tBlue + 1; let tishort = 0;
let socks = sBlue > sRed ? sRed + 1 : sBlue + 1; 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 (blueIsGrater) {
if (sBlue === sRed) socks = sRed + 1; 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(" "); return [tishort, socks].join(" ");
} }

Loading…
Cancel
Save