# my code stock.com # Mr.P & Mr.S by Mrinal Wahal

### Snippet options

Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

```print """
We pick two numbers a and b, so that 99 ≥ a ≥ b ≥ 2.
We tell Mr. P. the product a × b and Mr. S. the sum a + b.
Then Mr. S. and Mr. P. engage in the following dialog:

Mr. P.: I don’t know the numbers.

Mr. S.: I knew you didn’t know. I don’t know either.

Mr. P.: Now I know the numbers.

Mr. S.: Now I know them too.

Find the numbers a and b.
"""

import os

global list_of_crisis
list_of_crisis = [(a,b) for a in range(2,100) for b in range(2,100) if a >= b]

def map(operation):

Z = {}

for a,b in list_of_crisis:
z = operation(a,b)
if not z in Z: Z[z] = []
Z[z].append((a,b))

return Z

single_sol = lambda l: len(l) == 1

S = map(lambda a,b: a + b)
P = map(lambda a,b: a * b)

MrP_Dont = lambda p: not single_sol(P[p])
MrS_Dont = lambda s: not single_sol(S[s])

MrS_Do_MrP_Dont = lambda s: all([MrP_Dont(a*b) for a,b in S[s]])
MrP_Do = lambda p: single_sol([(a,b) for a,b in P[p] if MrS_Do_MrP_Dont(a + b)])
MrS_Do_MrP_Do = lambda s: single_sol([(a,b) for a,b in S[s] if MrP_Do(a*b)])

for a,b in list_of_crisis:
s,p = (a + b), (a * b)

if MrP_Dont(p)\
and MrS_Dont(s)\
and MrS_Do_MrP_Dont(s)\
and MrP_Do(p)\
and MrS_Do_MrP_Do(s): print "Numbers a & b Are ", a, ",", b, "Respectively."

os.system("pause")
```

### Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.