Jump to content
Urch Forums

rbode

Members
  • Posts

    2
  • Joined

Everything posted by rbode

  1. Hello Sam, I can't follow your reasoning but I am quiet sure it can't be 3 and 4 because in that case the person with the sum is not able to reply with "i know that you don't know the two numbers"; he would get 7 (3+4). From his perspection the numbers could then be 3+4 or 2+5 in the case of 2+5, the person with the product has 10 and should be able to know the combination as 10 can only be made out of 2x5 (both 2 and 5 are prime numbers). Best regards, Ronald
  2. Is the answer 4 and 13? I have heard this riddle a long time ago and tried to program is but didn't finnish it. Today I found the riddle back on this forum and programmed it again. My program comes with 4 and 13 (as the only solution), is this correct ? -Ronald This is the program: Sub main() For b = 2 To 98 For a = 2 To 98 If a + b ' Debug.Print a; b, If [u]Not[/u] P_knows(a * b) Then ' Debug.Print "P knows not", If S_knows_that(a + b) Then ' Debug.Print "S knows that", If P_knows_now(a * b) Then ' Debug.Print "P knows now", If S_knows_now(a + b) Then ' Debug.Print "S knows now", MsgBox Format(a) + ", " + Format(b) End If: End If: End If: End If: End If ' Debug.Print ' DoEvents Next a, b End Sub Function P_knows(Product As Integer) 'Does P know the numbers? t = 0 For I = 2 To Sqr(Product) 'Sqr to exclude the same numbers (e.g. 8 = 2 * 4 and 4 * 2) If Product Mod I = 0 Then t = t + 1 'P doesn't know if you can divide it by more then one number If t > 1 Then Exit For 'no need to check futher Next P_knows = t = 1 End Function Function S_knows_that(Sum) 'Does S know that P can't know the numbers? For I = 2 To Sum 2 ' 2 to exclude the same numbers (e.g. 17 = 2 + 15 and 15 + 2) If P_knows(i * (Sum - i)) Then 'for all the possible sums P should not be able to know the combination S_knows_that = False Exit Function End If Next i S_knows_that = True End Function Function P_knows_now(Product) 'Does P know the two numbers after S knows that P can't know them? t = 0 For I = 2 To Sqr(Product) If Product Mod I = 0 Then 'P can only say that if there is just one combination If I + (Product i) If t > 1 Then Exit For 'no need to check futher End If Next i P_knows_now = t = 1 End Function Function S_knows_now(Sum) 'Does S know the two numbers too after P knows them? t = 0 For I = 2 To Sum 2 'S can only say that if there is just one combination If P_knows_now(i * (Sum - i)) Then t = t + 1 If t > 1 Then Exit For 'no need to check futher Next i S_knows_now = t = 1 End Function
×
×
  • Create New...