A is introduced to B and asks him about his age.
B: I am the oldest of 3 brothers, 144 is the product of our ages, all integer numbers.
A: I still don't know your age.
B: The sum of all our ages is the number of the bus that brought you here.
A: I know the number, but not your age.
B: Only the youngest is red-headed.
A: Now I know all your ages.
And the ages are: ...
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
prod = 144
For low = 1 To prod ^ (1 / 3)
If prod Mod low = 0 Then
prod2 = prod / low
For middle = low To Sqr(prod2)
If prod2 Mod middle = 0 Then
high = prod2 / middle
tot = low + middle + high
Text1.Text = Text1.Text & mform(low, "##0") & mform(middle, "##0") & mform(high, "##0") & " " & mform(tot, "####0") & crlf
End If
Next
End If
Next low
Text1.Text = Text1.Text & crlf & " done"
End Sub
Function mform$(x, t$)
a$ = Format$(x, t$)
If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
mform$ = a$
End Function
After sorting on the total the output looks like
4 6 6 16
3 6 8 17 *
4 4 9 17 *
2 8 9 19 *
3 4 12 19 *
2 6 12 20
3 3 16 22
2 4 18 24
1 12 12 25
1 9 16 26
1 8 18 27
2 3 24 29
1 6 24 31
2 2 36 40
1 4 36 41
1 3 48 52
1 2 72 75
1 1 144 146
Only totals of 17 or 19 (marked *) could be ambiguous.
Since the fact that there is a youngest could only benefit distinguishing (4,4,9) from (3,6,8), the ages are 3, 6 and 8.
When reporting that the ages are all integer numbers, that could mean it's all their birthdays today, or it could mean the usual truncation to an integer as normally practiced.
If the latter, then the logic relies on A neglecting the fact that the two younger brothers could be 4 years exactly and 4 years 11 months, but the fact that B's last statement resolved his ambiguity indicates at least that the bus's number was 17. It's unlikely but possible that the ages are 4, 4 and 9. In fact, even in the case of twins, they keep track of which one is the younger, and in the case there are other siblings, the youngest.
Edited on September 23, 2015, 11:26 am
|
Posted by Charlie
on 2015-09-23 11:25:20 |