From 5cbd39a77c7c1f495d8e6630c10e580e45bb5626 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Sat, 25 Apr 2020 17:38:14 +0100 Subject: [PATCH] amicable.sage: compatibility with Python3-based sage. Signed-off-by: Daira Hopwood --- amicable.sage | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/amicable.sage b/amicable.sage index 829f70f..adcaa84 100644 --- a/amicable.sage +++ b/amicable.sage @@ -5,6 +5,8 @@ from traceback import print_exc from math import ceil from itertools import combinations +if sys.version_info[0] == 2: range = xrange + # Let Ep/Fp : y^2 = x^3 + bp # Let Eq/Fq : y^2 = x^3 + bq @@ -14,7 +16,7 @@ DEFAULT_TWOADICITY = 32 DEFAULT_STRETCH = 0 COEFFICIENT_RANGE = (5,) -#COEFFICIENT_RANGE = xrange(1, 10000) +#COEFFICIENT_RANGE = range(1, 10000) ACCEPTABLE_PRIMES = (5,) #ACCEPTABLE_PRIMES = Primes() @@ -47,12 +49,12 @@ def low_hamming_order(L, twoadicity, wid, processes): Tlen = (L-1)//4 Tbase = 1 << Tlen trailing_zeros = twoadicity+1 - for w in xrange(wid, Tlen-trailing_zeros, processes): - for Vc in combinations(xrange(trailing_zeros, Vlen), w): + for w in range(wid, Tlen-trailing_zeros, processes): + for Vc in combinations(range(trailing_zeros, Vlen), w): V = Vbase + sum([1 << i for i in Vc]) + 1 assert(((V-1)/2) % (1<