Four people knew all their respective ages (distinct integers).
One of them observed that if he were to multiply his age by any other age, in each of the 3 cases the product will be a permutation of the digits involved in the multiplication.
Please find all the 4 ages.
output:
21 6 60 87
explanation:
Those are the ages, the first being the speaker's.
21*6=126
21*60=1260
21*87=1827
ages from
DefDbl A-Z
Dim crlf$, age(4), digits$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For a1 = 4 To 111
age(1) = a1
digits = LTrim(Str(a1))
addOn (2)
Next a1
Text1.Text = Text1.Text & crlf & " done"
End Sub
Sub addOn(wh)
If wh = 2 Then st = 4 Else st = age(wh - 1) + 1
For a = st To 111
digits2$ = LTrim(Str(a))
prod = age(1) * a
p$ = LTrim(Str(prod))
d$ = digits + digits2
good = 1
If Len(d) = Len(p) Then
For i = 1 To Len(p)
ix = InStr(d, Mid(p, i, 1))
If ix = 0 Then good = 0: Exit For
d = Left(d, ix - 1) + Mid(d, ix + 1)
DoEvents
Next
If good Then
age(wh) = a
If wh = 4 Then
For i = 1 To 4
Text1.Text = Text1.Text & Str(age(i))
Next
Text1.Text = Text1.Text & crlf
Else
addOn (wh + 1)
End If
End If
End If
Next
End Sub
|
Posted by Charlie
on 2017-10-02 11:07:08 |