From 5c36c781a6cdc365a310dbba509d35373999b8af Mon Sep 17 00:00:00 2001 From: karthik Date: Tue, 29 Jul 2025 00:09:43 +0530 Subject: [PATCH] fix : TAN without box is working , box is having issue --- .../selection.service/selection.service.ts | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/btc-UI/src/app/components/selection.service/selection.service.ts b/btc-UI/src/app/components/selection.service/selection.service.ts index dc0cdce..efc7161 100644 --- a/btc-UI/src/app/components/selection.service/selection.service.ts +++ b/btc-UI/src/app/components/selection.service/selection.service.ts @@ -98,7 +98,7 @@ export class SelectionService { } updated.numbers = [...group1, '-', ...group2]; - updated.total = combinations * value * 10; // Value multiplier as per your code (10x) + updated.total = combinations * value * 10; break; } @@ -113,9 +113,23 @@ export class SelectionService { const group2 = updated.numbers.slice(dashIndices[0] + 1, dashIndices[1]).filter(n => typeof n === 'number') as number[]; const group3 = updated.numbers.slice(dashIndices[1] + 1).filter(n => typeof n === 'number') as number[]; - let combinations = group1.length * group2.length * group3.length; + let combinations = 0; + if (isBoxed) { - combinations = this.calculatePermutations(group1.length + group2.length + group3.length); + // Boxed: all unique numbers, nP3 + const allNums = Array.from(new Set([...group1, ...group2, ...group3])); + combinations = allNums.length >= 3 ? this.calculatePermutationsN(allNums.length, 3) : 0; + } else { + // Unboxed: only combinations where all chosen numbers are different + for (const a of group1) { + for (const b of group2) { + if (b === a) continue; + for (const c of group3) { + if (c === a || c === b) continue; + combinations++; + } + } + } } updated.total = combinations * value * 10; @@ -171,6 +185,15 @@ export class SelectionService { return n >= 2 ? n * (n - 1) : 0; } + private calculatePermutationsN(n: number, r: number): number { + if (n < r) return 0; + let result = 1; + for (let i = 0; i < r; i++) { + result *= (n - i); + } + return result; + } + private splitToLegs(numbers: (number | string)[], legCount: number): number[][] { const result: number[][] = []; let currentLeg: number[] = [];