Skip to content

Instantly share code, notes, and snippets.

@kyle-ilantzis
Created June 26, 2015 02:03
Show Gist options
  • Save kyle-ilantzis/6adb2fcbc15f081b116f to your computer and use it in GitHub Desktop.
Save kyle-ilantzis/6adb2fcbc15f081b116f to your computer and use it in GitHub Desktop.
polydivisible
from multiprocessing import Pool
import polydivisible
def ppoly(ab):
a,b = ab
polydivisible.main(["polydivisible",str(a),str(b)])
def main():
with Pool(4) as p:
bs = zip(range(26,51),range(26,51))
p.map(ppoly,bs)
print("Done")
if __name__ == '__main__':
main()
import sys
def usage(name):
print("usage:", name, "a b")
print("\tfind polydivisible numbers in bases [a,b]")
def poly(B):
Ds = [None] * (B-1)
Us = [False] * (B-1)
return polyLoop(B,Ds,Us,0,1)
def polyLoop(B,Ds,Us,A,N):
if N == B:
yield (B,Ds[:],A)
for I in range(1,B):
if Us[I-1]: continue
newA = A * B + I
if newA % N != 0: continue
Us[I-1] = True
Ds[N-1]= I
for p in polyLoop(B,Ds,Us,newA,N+1):
yield p
Ds[N-1] = None
Us[I-1] = False
def main(args):
if "-h" in args or "--help" in args or len(args) != 3:
usage(args[0])
return
dirtyA,dirtyB = args[1],args[2]
a,b = None,None
try: a = int(dirtyA,10)
except ValueError:
print("'a' value is not an integer:", dirtyA)
return
try: b = int(dirtyB,10)
except ValueError:
print("'b' value is not an integer:", dirtyB)
return
if a < 2:
print("'a' is to low, minimum is base 2:", a)
return
if a > b:
print("range [", a, ",", b, "] is not low to high")
return
for x in range(a,b+1):
print("base", x, "...")
for p in poly(x):
print(p)
if __name__ == '__main__':
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment