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:

    Wise Draco comes, deep in the midnight roll
    Of black artillery; he comes, though late;
    In code corroborating Calvin’s creed
    And cynic tyrannies of honest kings;
    He comes, nor parlies; and the Town, redeemed,
    Gives thanks devout; nor, being thankful, heeds
    The grimy slur on the Republic’s faith implied,
    Which holds that Man is naturally good,
    And—more—is Nature’s Roman, never to be
    scourged.
    Herman Melville (1819–1891)