From 1be559a552cc29481c9a341505ff58e02dd3cadb Mon Sep 17 00:00:00 2001 From: karthik Date: Mon, 28 Jul 2025 23:49:17 +0530 Subject: [PATCH] fix : QUI logic is working with and without box section --- .../selection.service/selection.service.ts | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 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 f1180e9..dc0cdce 100644 --- a/btc-UI/src/app/components/selection.service/selection.service.ts +++ b/btc-UI/src/app/components/selection.service/selection.service.ts @@ -1,4 +1,3 @@ -// ✅ Final SelectionService.ts with strict QUI logic import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; @@ -74,21 +73,32 @@ export class SelectionService { const group2 = updated.numbers.slice(dashIndex + 1).filter(n => typeof n === 'number') as number[]; let combinations = 0; + const set1 = new Set(group1); + const set2 = new Set(group2); + const uniqueUnion = new Set([...group1, ...group2]); - if (isBoxed) { - const uniq = Array.from(new Set([...group1, ...group2])); - combinations = this.calculateCombinations(uniq.length); // nC2 - updated.numbers = [...uniq, '-', ...uniq]; - } else { - for (const a of group1) { - for (const b of group2) { - if (a !== b) combinations++; - } - } - updated.numbers = [...group1, '-', ...group2]; + function setsAreEqual(a: Set, b: Set): boolean { + if (a.size !== b.size) return false; + for (let v of a) if (!b.has(v)) return false; + return true; } - updated.total = combinations * value * 10; + if (isBoxed || setsAreEqual(set1, set2)) { + combinations = uniqueUnion.size >= 2 ? (uniqueUnion.size * (uniqueUnion.size - 1)) / 2 : 0; + } else { + const pairSet = new Set(); + for (let a of set1) { + for (let b of set2) { + if (a === b) continue; + let key = a < b ? `${a},${b}` : `${b},${a}`; + pairSet.add(key); + } + } + combinations = pairSet.size; + } + + updated.numbers = [...group1, '-', ...group2]; + updated.total = combinations * value * 10; // Value multiplier as per your code (10x) break; }