perf: reduce retry limit from 3000 to 100 in problem generators
**Problem**: Large worksheets with constrained digit ranges were hanging. Example: 1000 single-digit problems with 100% regrouping = 168,608 retries for just 100 problems (1,686 retries/problem on average). **Root Cause**: Only 9 single-digit numbers (1-9) with 100% regrouping requirement = very few valid unique combinations. The 3000-retry limit meant millions of iterations for 1000-2000 problem worksheets. **Solution**: Reduced retry limit from 3000 to 100 in both: - generateProblems() (addition) - generateSubtractionProblems() This allows some duplicate problems when the constraint space is tight, but prevents the server from hanging on large worksheet generation. **Impact**: 100-page worksheets should now generate in seconds instead of timing out.
This commit is contained in:
parent
eec0aaf27e
commit
08fef59cc5
|
|
@ -283,9 +283,11 @@ export function generateProblems(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate problem with retries for uniqueness
|
// Generate problem with retries for uniqueness
|
||||||
|
// Reduced from 3000 to 100 - for large worksheets with constrained digit ranges,
|
||||||
|
// 3000 retries per problem = millions of iterations. Better to allow some duplicates.
|
||||||
let tries = 0
|
let tries = 0
|
||||||
let ok = false
|
let ok = false
|
||||||
while (tries++ < 3000 && !ok) {
|
while (tries++ < 100 && !ok) {
|
||||||
let a: number, b: number
|
let a: number, b: number
|
||||||
if (picked === 'both') {
|
if (picked === 'both') {
|
||||||
;[a, b] = generateBoth(rand, minDigits, maxDigits)
|
;[a, b] = generateBoth(rand, minDigits, maxDigits)
|
||||||
|
|
@ -613,9 +615,11 @@ export function generateSubtractionProblems(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate problem with retries for uniqueness
|
// Generate problem with retries for uniqueness
|
||||||
|
// Reduced from 3000 to 100 - for large worksheets with constrained digit ranges,
|
||||||
|
// 3000 retries per problem = millions of iterations. Better to allow some duplicates.
|
||||||
let tries = 0
|
let tries = 0
|
||||||
let ok = false
|
let ok = false
|
||||||
while (tries++ < 3000 && !ok) {
|
while (tries++ < 100 && !ok) {
|
||||||
let minuend: number, subtrahend: number
|
let minuend: number, subtrahend: number
|
||||||
if (picked === 'both') {
|
if (picked === 'both') {
|
||||||
;[minuend, subtrahend] = generateBothBorrow(rand, minDigits, maxDigits)
|
;[minuend, subtrahend] = generateBothBorrow(rand, minDigits, maxDigits)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue