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:

    ... the self respect of individuals ought to make them demand of their leaders conformity with an agreed-upon code of ethics and moral conduct.
    Mary Barnett Gilson (1877–?)