A puzzle by Princeton mathematician John Horton Conway:
Last night I sat behind two wizards on a bus, and overheard the following:
A: I have a positive integral number of children, whose ages are positive integers, the sum of which is the number of this bus, while the product is my own age.
B: How interesting! Perhaps if you told me your age and the number of your children, I could work out their individual ages?
A: No.
B: Aha! AT LAST I know how old you are!
Rem: Taking in account the fatherhood limitations, this is uniquely solvable.
DefDbl A-Z
Dim crlf$, n, h(9), sum, prod
Private Sub Form_Load()
Form1.Visible = True
Open "incredible but solvable.txt" For Output As #2
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
prod = 1
For n = 2 To 9
addOn 1
Next n
Close
' ********* sorting takes place outside the program and the program started again
' ********* this time with the below code in place.
Open "incredible but solvable sorted.txt" For Input As #1
Do
pr$ = l$
Line Input #1, l$
If Left(l, 13) = Left(pr, 13) Then
Text1.Text = Text1.Text & pr & crlf & l & crlf & crlf
End If
Loop Until EOF(1)
Close
Text1.Text = Text1.Text & crlf & " done"
End Sub
Sub addOn(wh)
If wh = 1 Then st = 1 Else st = h(wh - 1)
For newOne = st To 25
sum = sum + newOne
prod = prod * newOne
h(wh) = newOne
If prod < 100 Then
If wh = n Then
If prod - 15 > h(n) Then
Print #2, mform(sum, "####0"); mform(prod, "####0"); mform(n, "#0"); " ";
For i = 1 To n
Print #2, mform(h(i), "##0");
Next
Print #2,
End If
Else
addOn wh + 1
End If
End If
sum = sum - newOne
prod = prod / newOne
Next
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
The first portion of the program produces a file. That file was sorted and then read in by a further portion of the program, added after the first part was run and the output file sorted. It includes all possibilities of 2 to 9 children, where the age of the father (product of the kids' ages) did not exceed 99 and none of the children were over 25 (unlikely for a 52-year old to have a 2 year old and a 26 year old).
The sorted file, read by the second part, is:
father's
bus# age # ages
(sum) (prod) children
9 24 3 2 3 4
9 24 4 2 2 2 3
9 27 3 3 3 3
10 24 2 4 6
10 24 3 2 2 6
10 24 4 1 2 3 4
10 24 5 1 2 2 2 3
10 25 2 5 5
10 27 4 1 3 3 3
10 30 3 2 3 5
10 32 3 2 4 4
10 32 4 2 2 2 4
10 32 5 2 2 2 2 2
10 36 3 3 3 4
10 36 4 2 2 3 3
11 24 2 3 8
11 24 3 1 4 6
11 24 4 1 2 2 6
11 24 5 1 1 2 3 4
11 24 6 1 1 2 2 2 3
11 25 3 1 5 5
11 27 5 1 1 3 3 3
11 28 2 4 7
11 28 3 2 2 7
11 30 2 5 6
11 30 4 1 2 3 5
11 32 4 1 2 4 4
11 32 5 1 2 2 2 4
11 32 6 1 2 2 2 2 2
11 36 3 2 3 6
11 36 4 1 3 3 4
11 36 5 1 2 2 3 3
11 40 3 2 4 5
11 40 4 2 2 2 5
11 45 3 3 3 5
11 48 3 3 4 4
11 48 4 2 2 3 4
11 48 5 2 2 2 2 3
11 54 4 2 3 3 3
12 24 3 1 3 8
12 24 4 1 1 4 6
12 24 5 1 1 2 2 6
12 24 6 1 1 1 2 3 4
12 24 7 1 1 1 2 2 2 3
12 25 4 1 1 5 5
12 27 2 3 9
12 27 6 1 1 1 3 3 3
12 28 3 1 4 7
12 28 4 1 2 2 7
12 30 3 1 5 6
12 30 5 1 1 2 3 5
12 32 2 4 8
12 32 3 2 2 8
12 32 5 1 1 2 4 4
12 32 6 1 1 2 2 2 4
12 32 7 1 1 2 2 2 2 2
12 35 2 5 7
12 36 2 6 6
12 36 4 1 2 3 6
12 36 5 1 1 3 3 4
12 36 6 1 1 2 2 3 3
12 40 4 1 2 4 5
12 40 5 1 2 2 2 5
12 42 3 2 3 7
12 45 4 1 3 3 5
12 48 3 2 4 6
12 48 4 1 3 4 4
12 48 4 2 2 2 6
12 48 5 1 2 2 3 4
12 48 6 1 2 2 2 2 3
12 50 3 2 5 5
12 54 3 3 3 6
12 54 5 1 2 3 3 3
12 60 3 3 4 5
12 60 4 2 2 3 5
12 64 3 4 4 4
12 64 4 2 2 4 4
12 64 5 2 2 2 2 4
12 64 6 2 2 2 2 2 2
12 72 4 2 3 3 4
12 72 5 2 2 2 3 3
12 81 4 3 3 3 3
13 24 4 1 1 3 8
13 24 5 1 1 1 4 6
13 24 6 1 1 1 2 2 6
13 24 7 1 1 1 1 2 3 4
13 24 8 1 1 1 1 2 2 2 3
13 25 5 1 1 1 5 5
13 27 3 1 3 9
13 27 7 1 1 1 1 3 3 3
13 28 4 1 1 4 7
13 28 5 1 1 2 2 7
13 30 2 3 10
13 30 4 1 1 5 6
13 30 6 1 1 1 2 3 5
13 32 3 1 4 8
13 32 4 1 2 2 8
13 32 6 1 1 1 2 4 4
13 32 7 1 1 1 2 2 2 4
13 32 8 1 1 1 2 2 2 2 2
13 35 3 1 5 7
13 36 2 4 9
13 36 3 1 6 6
13 36 3 2 2 9
13 36 5 1 1 2 3 6
13 36 6 1 1 1 3 3 4
13 36 7 1 1 1 2 2 3 3
13 40 2 5 8
13 40 5 1 1 2 4 5
13 40 6 1 1 2 2 2 5
13 42 2 6 7
13 42 4 1 2 3 7
13 45 5 1 1 3 3 5
13 48 3 2 3 8
13 48 4 1 2 4 6
13 48 5 1 1 3 4 4
13 48 5 1 2 2 2 6
13 48 6 1 1 2 2 3 4
13 48 7 1 1 2 2 2 2 3
13 50 4 1 2 5 5
13 54 4 1 3 3 6
13 54 6 1 1 2 3 3 3
13 56 3 2 4 7
13 56 4 2 2 2 7
13 60 3 2 5 6
13 60 4 1 3 4 5
13 60 5 1 2 2 3 5
13 63 3 3 3 7
13 64 4 1 4 4 4
13 64 5 1 2 2 4 4
13 64 6 1 2 2 2 2 4
13 64 7 1 2 2 2 2 2 2
13 72 3 3 4 6
13 72 4 2 2 3 6
13 72 5 1 2 3 3 4
13 72 6 1 2 2 2 3 3
13 75 3 3 5 5
13 80 3 4 4 5
13 80 4 2 2 4 5
13 80 5 2 2 2 2 5
13 81 5 1 3 3 3 3
13 90 4 2 3 3 5
13 96 4 2 3 4 4
13 96 5 2 2 2 3 4
13 96 6 2 2 2 2 2 3
14 24 5 1 1 1 3 8
14 24 6 1 1 1 1 4 6
14 24 7 1 1 1 1 2 2 6
14 24 8 1 1 1 1 1 2 3 4
14 24 9 1 1 1 1 1 2 2 2 3
14 25 6 1 1 1 1 5 5
14 27 4 1 1 3 9
14 27 8 1 1 1 1 1 3 3 3
14 28 5 1 1 1 4 7
14 28 6 1 1 1 2 2 7
14 30 3 1 3 10
14 30 5 1 1 1 5 6
14 30 7 1 1 1 1 2 3 5
14 32 4 1 1 4 8
14 32 5 1 1 2 2 8
14 32 7 1 1 1 1 2 4 4
14 32 8 1 1 1 1 2 2 2 4
14 32 9 1 1 1 1 2 2 2 2 2
14 33 2 3 11
14 35 4 1 1 5 7
14 36 3 1 4 9
14 36 4 1 1 6 6
14 36 4 1 2 2 9
14 36 6 1 1 1 2 3 6
14 36 7 1 1 1 1 3 3 4
14 36 8 1 1 1 1 2 2 3 3
14 40 2 4 10
14 40 3 1 5 8
14 40 3 2 2 10
14 40 6 1 1 1 2 4 5
14 40 7 1 1 1 2 2 2 5
14 42 3 1 6 7
14 42 5 1 1 2 3 7
14 45 2 5 9
14 45 6 1 1 1 3 3 5
14 48 2 6 8
14 48 4 1 2 3 8
14 48 5 1 1 2 4 6
14 48 6 1 1 1 3 4 4
14 48 6 1 1 2 2 2 6
14 48 7 1 1 1 2 2 3 4
14 48 8 1 1 1 2 2 2 2 3
14 49 2 7 7
14 50 5 1 1 2 5 5
14 54 3 2 3 9
14 54 5 1 1 3 3 6
14 54 7 1 1 1 2 3 3 3
14 56 4 1 2 4 7
14 56 5 1 2 2 2 7
14 60 4 1 2 5 6
14 60 5 1 1 3 4 5
14 60 6 1 1 2 2 3 5
14 63 4 1 3 3 7
14 64 3 2 4 8
14 64 4 2 2 2 8
14 64 5 1 1 4 4 4
14 64 6 1 1 2 2 4 4
14 64 7 1 1 2 2 2 2 4
14 64 8 1 1 2 2 2 2 2 2
14 70 3 2 5 7
14 72 3 2 6 6
14 72 3 3 3 8
14 72 4 1 3 4 6
14 72 5 1 2 2 3 6
14 72 6 1 1 2 3 3 4
14 72 7 1 1 2 2 2 3 3
14 75 4 1 3 5 5
14 80 4 1 4 4 5
14 80 5 1 2 2 4 5
14 80 6 1 2 2 2 2 5
14 81 6 1 1 3 3 3 3
14 84 3 3 4 7
14 84 4 2 2 3 7
14 90 3 3 5 6
14 90 5 1 2 3 3 5
14 96 3 4 4 6
14 96 4 2 2 4 6
14 96 5 1 2 3 4 4
14 96 5 2 2 2 2 6
14 96 6 1 2 2 2 3 4
14 96 7 1 2 2 2 2 2 3
15 24 6 1 1 1 1 3 8
15 24 7 1 1 1 1 1 4 6
15 24 8 1 1 1 1 1 2 2 6
15 24 9 1 1 1 1 1 1 2 3 4
15 25 7 1 1 1 1 1 5 5
15 27 5 1 1 1 3 9
15 27 9 1 1 1 1 1 1 3 3 3
15 28 6 1 1 1 1 4 7
15 28 7 1 1 1 1 2 2 7
15 30 4 1 1 3 10
15 30 6 1 1 1 1 5 6
15 30 8 1 1 1 1 1 2 3 5
15 32 5 1 1 1 4 8
15 32 6 1 1 1 2 2 8
15 32 8 1 1 1 1 1 2 4 4
15 32 9 1 1 1 1 1 2 2 2 4
15 33 3 1 3 11
15 35 5 1 1 1 5 7
15 36 2 3 12
15 36 4 1 1 4 9
15 36 5 1 1 1 6 6
15 36 5 1 1 2 2 9
15 36 7 1 1 1 1 2 3 6
15 36 8 1 1 1 1 1 3 3 4
15 36 9 1 1 1 1 1 2 2 3 3
15 40 3 1 4 10
15 40 4 1 1 5 8
15 40 4 1 2 2 10
15 40 7 1 1 1 1 2 4 5
15 40 8 1 1 1 1 2 2 2 5
15 42 4 1 1 6 7
15 42 6 1 1 1 2 3 7
15 44 2 4 11
15 44 3 2 2 11
15 45 3 1 5 9
15 45 7 1 1 1 1 3 3 5
15 48 3 1 6 8
15 48 5 1 1 2 3 8
15 48 6 1 1 1 2 4 6
15 48 7 1 1 1 1 3 4 4
15 48 7 1 1 1 2 2 2 6
15 48 8 1 1 1 1 2 2 3 4
15 48 9 1 1 1 1 2 2 2 2 3
15 49 3 1 7 7
15 50 2 5 10
15 50 6 1 1 1 2 5 5
15 54 2 6 9
15 54 4 1 2 3 9
15 54 6 1 1 1 3 3 6
15 54 8 1 1 1 1 2 3 3 3
15 56 2 7 8
15 56 5 1 1 2 4 7
15 56 6 1 1 2 2 2 7
15 60 3 2 3 10
15 60 5 1 1 2 5 6
15 60 6 1 1 1 3 4 5
15 60 7 1 1 1 2 2 3 5
15 63 5 1 1 3 3 7
15 64 4 1 2 4 8
15 64 5 1 2 2 2 8
15 64 6 1 1 1 4 4 4
15 64 7 1 1 1 2 2 4 4
15 64 8 1 1 1 2 2 2 2 4
15 64 9 1 1 1 2 2 2 2 2 2
15 70 4 1 2 5 7
15 72 3 2 4 9
15 72 4 1 2 6 6
15 72 4 1 3 3 8
15 72 4 2 2 2 9
15 72 5 1 1 3 4 6
15 72 6 1 1 2 2 3 6
15 72 7 1 1 1 2 3 3 4
15 72 8 1 1 1 2 2 2 3 3
15 75 5 1 1 3 5 5
15 80 3 2 5 8
15 80 5 1 1 4 4 5
15 80 6 1 1 2 2 4 5
15 80 7 1 1 2 2 2 2 5
15 81 3 3 3 9
15 81 7 1 1 1 3 3 3 3
15 84 3 2 6 7
15 84 4 1 3 4 7
15 84 5 1 2 2 3 7
15 90 4 1 3 5 6
15 90 6 1 1 2 3 3 5
15 96 3 3 4 8
15 96 4 1 4 4 6
15 96 4 2 2 3 8
15 96 5 1 2 2 4 6
15 96 6 1 1 2 3 4 4
15 96 6 1 2 2 2 2 6
15 96 7 1 1 2 2 2 3 4
15 96 8 1 1 2 2 2 2 2 3
16 24 7 1 1 1 1 1 3 8
16 24 8 1 1 1 1 1 1 4 6
16 24 9 1 1 1 1 1 1 2 2 6
16 25 8 1 1 1 1 1 1 5 5
16 27 6 1 1 1 1 3 9
16 28 7 1 1 1 1 1 4 7
16 28 8 1 1 1 1 1 2 2 7
16 30 5 1 1 1 3 10
16 30 7 1 1 1 1 1 5 6
16 30 9 1 1 1 1 1 1 2 3 5
16 32 6 1 1 1 1 4 8
16 32 7 1 1 1 1 2 2 8
16 32 9 1 1 1 1 1 1 2 4 4
16 33 4 1 1 3 11
16 35 6 1 1 1 1 5 7
16 36 3 1 3 12
16 36 5 1 1 1 4 9
16 36 6 1 1 1 1 6 6
16 36 6 1 1 1 2 2 9
16 36 8 1 1 1 1 1 2 3 6
16 36 9 1 1 1 1 1 1 3 3 4
16 39 2 3 13
16 40 4 1 1 4 10
16 40 5 1 1 1 5 8
16 40 5 1 1 2 2 10
16 40 8 1 1 1 1 1 2 4 5
16 40 9 1 1 1 1 1 2 2 2 5
16 42 5 1 1 1 6 7
16 42 7 1 1 1 1 2 3 7
16 44 3 1 4 11
16 44 4 1 2 2 11
16 45 4 1 1 5 9
16 45 8 1 1 1 1 1 3 3 5
16 48 2 4 12
16 48 3 2 2 12
16 48 4 1 1 6 8
16 48 6 1 1 1 2 3 8
16 48 7 1 1 1 1 2 4 6
16 48 8 1 1 1 1 1 3 4 4
16 48 8 1 1 1 1 2 2 2 6
16 48 9 1 1 1 1 1 2 2 3 4
16 49 4 1 1 7 7
16 50 3 1 5 10
16 50 7 1 1 1 1 2 5 5
16 54 3 1 6 9
16 54 5 1 1 2 3 9
16 54 7 1 1 1 1 3 3 6
16 54 9 1 1 1 1 1 2 3 3 3
16 55 2 5 11
16 56 3 1 7 8
16 56 6 1 1 1 2 4 7
16 56 7 1 1 1 2 2 2 7
16 60 2 6 10
16 60 4 1 2 3 10
16 60 6 1 1 1 2 5 6
16 60 7 1 1 1 1 3 4 5
16 60 8 1 1 1 1 2 2 3 5
16 63 2 7 9
16 63 6 1 1 1 3 3 7
16 64 2 8 8
16 64 5 1 1 2 4 8
16 64 6 1 1 2 2 2 8
16 64 7 1 1 1 1 4 4 4
16 64 8 1 1 1 1 2 2 4 4
16 64 9 1 1 1 1 2 2 2 2 4
16 66 3 2 3 11
16 70 5 1 1 2 5 7
16 72 4 1 2 4 9
16 72 5 1 1 2 6 6
16 72 5 1 1 3 3 8
16 72 5 1 2 2 2 9
16 72 6 1 1 1 3 4 6
16 72 7 1 1 1 2 2 3 6
16 72 8 1 1 1 1 2 3 3 4
16 72 9 1 1 1 1 2 2 2 3 3
16 75 6 1 1 1 3 5 5
16 80 3 2 4 10
16 80 4 1 2 5 8
16 80 4 2 2 2 10
16 80 6 1 1 1 4 4 5
16 80 7 1 1 1 2 2 4 5
16 80 8 1 1 1 2 2 2 2 5
16 81 4 1 3 3 9
16 81 8 1 1 1 1 3 3 3 3
16 84 4 1 2 6 7
16 84 5 1 1 3 4 7
16 84 6 1 1 2 2 3 7
16 90 3 2 5 9
16 90 3 3 3 10
16 90 5 1 1 3 5 6
16 90 7 1 1 1 2 3 3 5
16 96 3 2 6 8
16 96 4 1 3 4 8
16 96 5 1 1 4 4 6
16 96 5 1 2 2 3 8
16 96 6 1 1 2 2 4 6
16 96 7 1 1 1 2 3 4 4
16 96 7 1 1 2 2 2 2 6
16 96 8 1 1 1 2 2 2 3 4
16 96 9 1 1 1 2 2 2 2 2 3
16 98 3 2 7 7
17 24 8 1 1 1 1 1 1 3 8
17 24 9 1 1 1 1 1 1 1 4 6
17 25 9 1 1 1 1 1 1 1 5 5
17 27 7 1 1 1 1 1 3 9
17 28 8 1 1 1 1 1 1 4 7
17 28 9 1 1 1 1 1 1 2 2 7
17 30 6 1 1 1 1 3 10
17 30 8 1 1 1 1 1 1 5 6
17 32 7 1 1 1 1 1 4 8
17 32 8 1 1 1 1 1 2 2 8
17 33 5 1 1 1 3 11
17 35 7 1 1 1 1 1 5 7
17 36 4 1 1 3 12
17 36 6 1 1 1 1 4 9
17 36 7 1 1 1 1 1 6 6
17 36 7 1 1 1 1 2 2 9
17 36 9 1 1 1 1 1 1 2 3 6
17 39 3 1 3 13
17 40 5 1 1 1 4 10
17 40 6 1 1 1 1 5 8
17 40 6 1 1 1 2 2 10
17 40 9 1 1 1 1 1 1 2 4 5
17 42 2 3 14
17 42 6 1 1 1 1 6 7
17 42 8 1 1 1 1 1 2 3 7
17 44 4 1 1 4 11
17 44 5 1 1 2 2 11
17 45 5 1 1 1 5 9
17 45 9 1 1 1 1 1 1 3 3 5
17 48 3 1 4 12
17 48 4 1 2 2 12
17 48 5 1 1 1 6 8
17 48 7 1 1 1 1 2 3 8
17 48 8 1 1 1 1 1 2 4 6
17 48 9 1 1 1 1 1 1 3 4 4
17 48 9 1 1 1 1 1 2 2 2 6
17 49 5 1 1 1 7 7
17 50 4 1 1 5 10
17 50 8 1 1 1 1 1 2 5 5
17 52 2 4 13
17 52 3 2 2 13
17 54 4 1 1 6 9
17 54 6 1 1 1 2 3 9
17 54 8 1 1 1 1 1 3 3 6
17 55 3 1 5 11
17 56 4 1 1 7 8
17 56 7 1 1 1 1 2 4 7
17 56 8 1 1 1 1 2 2 2 7
17 60 2 5 12
17 60 3 1 6 10
17 60 5 1 1 2 3 10
17 60 7 1 1 1 1 2 5 6
17 60 8 1 1 1 1 1 3 4 5
17 60 9 1 1 1 1 1 2 2 3 5
17 63 3 1 7 9
17 63 7 1 1 1 1 3 3 7
17 64 3 1 8 8
17 64 6 1 1 1 2 4 8
17 64 7 1 1 1 2 2 2 8
17 64 8 1 1 1 1 1 4 4 4
17 64 9 1 1 1 1 1 2 2 4 4
17 66 2 6 11
17 66 4 1 2 3 11
17 70 2 7 10
17 70 6 1 1 1 2 5 7
17 72 2 8 9
17 72 3 2 3 12
17 72 5 1 1 2 4 9
17 72 6 1 1 1 2 6 6
17 72 6 1 1 1 3 3 8
17 72 6 1 1 2 2 2 9
17 72 7 1 1 1 1 3 4 6
17 72 8 1 1 1 1 2 2 3 6
17 72 9 1 1 1 1 1 2 3 3 4
17 75 7 1 1 1 1 3 5 5
17 80 4 1 2 4 10
17 80 5 1 1 2 5 8
17 80 5 1 2 2 2 10
17 80 7 1 1 1 1 4 4 5
17 80 8 1 1 1 1 2 2 4 5
17 80 9 1 1 1 1 2 2 2 2 5
17 81 5 1 1 3 3 9
17 81 9 1 1 1 1 1 3 3 3 3
17 84 5 1 1 2 6 7
17 84 6 1 1 1 3 4 7
17 84 7 1 1 1 2 2 3 7
17 88 3 2 4 11
17 88 4 2 2 2 11
17 90 4 1 2 5 9
17 90 4 1 3 3 10
17 90 6 1 1 1 3 5 6
17 90 8 1 1 1 1 2 3 3 5
17 96 4 1 2 6 8
17 96 5 1 1 3 4 8
17 96 6 1 1 1 4 4 6
17 96 6 1 1 2 2 3 8
17 96 7 1 1 1 2 2 4 6
17 96 8 1 1 1 1 2 3 4 4
17 96 8 1 1 1 2 2 2 2 6
17 96 9 1 1 1 1 2 2 2 3 4
17 98 4 1 2 7 7
17 99 3 3 3 11
18 24 9 1 1 1 1 1 1 1 3 8
18 27 8 1 1 1 1 1 1 3 9
18 28 9 1 1 1 1 1 1 1 4 7
18 30 7 1 1 1 1 1 3 10
18 30 9 1 1 1 1 1 1 1 5 6
18 32 2 2 16
18 32 8 1 1 1 1 1 1 4 8
18 32 9 1 1 1 1 1 1 2 2 8
18 33 6 1 1 1 1 3 11
18 35 8 1 1 1 1 1 1 5 7
18 36 5 1 1 1 3 12
18 36 7 1 1 1 1 1 4 9
18 36 8 1 1 1 1 1 1 6 6
18 36 8 1 1 1 1 1 2 2 9
18 39 4 1 1 3 13
18 40 6 1 1 1 1 4 10
18 40 7 1 1 1 1 1 5 8
18 40 7 1 1 1 1 2 2 10
-- continued next comment --
Edited on October 30, 2015, 3:28 pm
|
Posted by Charlie
on 2015-10-30 15:23:50 |