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:

    Faultless honesty is a sine qua non of business life. Not alone the honesty according to the moral code and the Bible. When I speak of honesty I refer to the small, hidden, evasive meannesses of our natures. I speak of the honesty of ourselves to ourselves.
    Alice Foote MacDougall (1867–1945)