4 ms·
Here's a generator version. It is not as terse, but seems to run faster. [Edit:] Or not faster in entirety, but finds solution more quickly during the iterati
by hcrisp 10y ago
Here's a generator version. It is not as terse, but seems to run faster. [Edit:] Or not faster in entirety, but finds solution more quickly during the iteration.
from fractions import Fraction as F
def thor():
for th in range(1, 27):
for o in range(1, 27):
for r in range(1, 27):
if 2*(th**2) + o**2 + r**2 == 1000:
yield th, o, r
def sz(thors):
for th, o, r in thors:
for s in range(1, 27):
for z in range(1, 27):
if (th**2 * z**2 * (s - z) + s**2) == 7225:
yield th, o, r, s, z
def gdxi(szs):
for th, o, r, s, z in szs:
for g in range(1, 27):
for d in range(1, 27):
for xi in range(1, 27):
if (g-1)**2 + d**2 + xi**2 - xi == 600:
yield th, o, r, s, z, g, d, xi
def eti(gdxis):
for th, o, r, s, z, g, d, xi in gdxis:
for (et, i) in (
(xi-7, xi-11), (xi-11,xi-7), (xi+7, xi+11), (xi+11, xi+7)):
if 0 < et <= 26 and 0 < i <= 26:
yield th, o, r, s, z, g, d, xi, et, i
def amupi(etis):
for th, o, r, s, z, g, d, xi, et, i in etis:
for (a, mu) in ((4, 1), (2, 2), (1, 4)):
for pi in range(1, 27):
if a*(a+pi) == 4 * g:
yield th, o, r, s, z, g, d, xi, et, i, a, mu, pi
def kben(amupis):
for th, o, r, s, z, g, d, xi, et, i, a, mu, pi in amupis:
for k in (3,4):
for b in range(1, 27):
for e in range(1, 27):
for n in range(1, 27):
if b**3 + z**3 + n**3 + o**9 == 1997:
if (F(a, k)**2 + F(b, n)**2 + F(d, xi)**2 +
F(e, pi)**2 + F(et, mu)**2 +
F(i, s)**2 == 6):
yield (a, b, g, d, e, z, et, th, i,
k, th, mu, n, xi, o, pi, r, s)
thors = thor()
szs = sz(thors)
gdxis = gdxi(szs)
etis = eti(gdxis)
amupis = amupi(etis)
results = kben(amupis)
print('\t'.join(('a', 'b', 'g', 'd', 'e', 'z', 'et', 'th',
'i', 'k', 'l', 'mu', 'n', 'xi', 'o', 'pi', 'r', 's')))
for r in results:
print('\t'.join(map(str, r)))