Impossible Puzzle - Python Code

Python Code

Here is a program written in python that proves that the above solution is unique.

limit=100 #before they talk any x*y where 11 are allowed SNotAllowed1={} for x in range(2,limit): for y in range(x+1,limit-x): if PAllowed1==1 : SNotAllowed1=1 # when S says I don't know, only S's that are not in the domain of SNotAllowed1 are allowed PAllowed2={} for n in range(2,limit): if n not in SNotAllowed1: for x in range(2,n/2+1): if x*(n-x) in PAllowed1 and PAllowed1 > 1: if x*(n-x) in PAllowed2: PAllowed2 +=1 else: PAllowed2 =1 # only the P's that can by split to two x,y where x+y is allowed in only 1 way are allowed, i.e., PAllowed2==1 SAllowed2={} for n in range(2,limit): if n not in SNotAllowed1: for x in range(2,n/2+1): if x*(n-x) in PAllowed2 and PAllowed2 == 1: if n in SAllowed2: SAllowed2 +=1 else: SAllowed2 =1 # since S knows the answer now the split can only be done in one way, so only S where SAllowed2==1 for n in SAllowed2: if SAllowed2 ==1: for x in range(2,n/2+1): if x*(n-x) in PAllowed2 and PAllowed2 == 1: print '(S,P) = ( %d, %d ), (x,y)= ( %d, %d )' % (n, x*(n-x), x, n-x)

Read more about this topic:  Impossible Puzzle

Famous quotes containing the word code:

    Many people will say to working mothers, in effect, “I don’t think you can have it all.” The phrase for “have it all” is code for “have your cake and eat it too.” What these people really mean is that achievement in the workplace has always come at a price—usually a significant personal price; conversely, women who stayed home with their children were seen as having sacrificed a great deal of their own ambition for their families.
    Anne C. Weisberg (20th century)