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:

    Hollywood keeps before its child audiences a string of glorified young heroes, everyone of whom is an unhesitating and violent Anarchist. His one answer to everything that annoys him or disparages his country or his parents or his young lady or his personal code of manly conduct is to give the offender a “sock” in the jaw.... My observation leads me to believe that it is not the virtuous people who are good at socking jaws.
    George Bernard Shaw (1856–1950)