// export function tiShortChoser(
//   tB: number,
//   tR: number,
//   sB: number,
//   sR: number,
// ) {
//   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;
//   const isBlue = tB === sB && !tIsEquale && !sIsEquale;
//   const isRed = tR === sR && !tIsEquale && !sIsEquale;

//   if (blueIsGrater) {
//     tishort = sIsEquale && !isEquaal ? 1 : tR + 1;
//     socks = tIsEquale || isEquaal ? 1 : sR + 1;
//   } else {
//     tishort = sIsEquale && !isEquaal ? 1 : tB + 1;
//     socks = tIsEquale || isEquaal ? 1 : 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 (isRed) {
//     tishort = tR + 1;
//     socks = 1;
//   }

//   if (isBlue) {
//     tishort = tB + 1;
//     socks = 1;
//   }

//   if (isBlue && isRed && (tB !== 0 || sB !== 0)) {
//     tishort = 2;
//     socks = 1;
//   }

//   return [tishort, socks].join(" ");
// }

export function tiShortChoser(
  tB: number,
  tR: number,
  sB: number,
  sR: number,
) {
  let tishort = 0;
  let socks = 0;
  const ans: number[][] = [];

  if (tB > 0 && sB > 0) {
    tishort = tR + 1;
    socks = sR + 1;
    ans.push([tishort, socks])
  }

  if (tR > 0 && sR > 0) {
    tishort = tB + 1;
    socks = sB + 1;
    ans.push([tishort, socks])
  }

  if (tB > 0 && tR > 0) {
    tishort = Math.max(tB, tR) + 1;
    socks = 1;
    ans.push([tishort, socks])
  }

  if (sB > 0 && sR > 0) {
    tishort = 1;
    socks = Math.max(sB, sR) + 1;
    ans.push([tishort, socks])
  }

  const result = ans.reduce((acc, currentValue) => {
    const [t, s] = currentValue;
    const [minT, minS] = acc;
    const minSum = minT + minS;
    const curSum = t + s;
    if (acc.length === 0) return currentValue;
    return (curSum < minSum) ? currentValue : acc;
  }, [] as number[])

  return result.join(" ");
}

