Skip to content

Instantly share code, notes, and snippets.

@iconjack
Created May 16, 2014 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iconjack/5cf6234217a01775a3b1 to your computer and use it in GitHub Desktop.
Save iconjack/5cf6234217a01775a3b1 to your computer and use it in GitHub Desktop.
from math import sqrt
from itertools import permutations
def squarable(sides):
area = sum(map(lambda (a,b): a*b, sides))
S = sqrt(area)
if S == int(S):
# check Ken's conditions
(H,A),(B,C),(D,E),(F,G),(X,Y) = sides
return S == (A+B) == (C+D) == (E+F) == (G+H) == (F+X+B) == (H+Y+D) and \
(A == F+X) and (C == H+Y) and (E == B+X) and (G == D+Y)
solutions = set()
for (H,A,B,C,D,E,F,G,X,Y) in permutations((1,2,3,4,5,6,7,8,9,10)):
sides = ((H,A),(B,C),(D,E),(F,G),(X,Y))
if squarable(sides):
sol = sorted(map(lambda (a,b): (min(a,b), max(a,b)), sides))
solutions.add(tuple(sol))
print "%d solutions" % len(solutions)
for sol in solutions: print sol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment