python - Backtracking to generate all numbers within constraint -
i trying create function generates numbers can formed through combination of primes satisfy constraint of being within 99% of number , less or equal number. primes [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43] , exponents [39, 19, 9 , 6, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1]
the code have uses 1 of each prime , stops, 2^1*3^1*5^1*...*17^1 or something, doesn't increment exponents. not sure wrong here, don't know problem is. here code
def rec(start): global freqa global global exp if start >=length:return true print a," ",freqa if a>= int(0.99*curt): in xrange(length): exp[i]=exponents[i]-freqa[i] rec1(0) in xrange(exponents[start]): freqa[start]+=1 a*=primes[start] if a<=curt , rec(start+1): return true freqa[start]-=1 a/=primes[start] return false
line
exp[i]=exponents[i]-freqa[i]
not in loop
just in case: 17! = 355 687 428 096 000
Comments
Post a Comment