A certain tribe had an interesting kind of annual festival, in which every male member of the tribe (regardless of age) had to contribute a levy of grain into the tribal store. Their unit of weight was roughly the same as our pound avoirdupois, and each tribesman had to contribute one pound of grain for every year of his age.
The contributions were weighed on the tribe's ceremonial scales, using a set of seven ceremonial stones. Each of these weighed an integral number of pounds, and it was an essential part of the ritual that not more than three of them should be used for each weighing, though they need not all be in the same pan.
If ever a tribesman lived to such an age that his contribution could no longer be weighed by using three or fewer stones, the levy of grain would terminate forever. And in the previous year, one old man had died only a few months short of attaining this critical age, greatly to the relief of the headman of the tribe.
It has been determined that the stones can measure the maximum age. What is this age and what were the weights of the seven ceremonial stones?
For speed I chose VB in preference to QB. (In particular VB 5.0).
Dim h(7), which, bestH(7), highTot
Sub try(lbs)
h(which) = lbs
If which = 3 Then
Cls
Print h(1), h(2), h(3)
Print highTot
For i = 1 To 7
Print bestH(i);
Next
Print
DoEvents
End If
If which = 7 Then
ReDim had(200)
For i = 1 To 7
hi = h(i)
had(hi) = 1
For j = i + 1 To 7
hj = h(j)
hij = hi + hj
himj = Abs(hi - hj)
If hij <= 200 Then had(hij) = 1
had(himj) = 1
For k = j + 1 To 7
hk = h(k)
hijk = hij + hk
hijmk = Abs(hij - hk)
himjk = himj + hk
himjmk = Abs(himj - hk)
If hijk <= 200 Then had(hijk) = 1
If hijmk <= 200 Then had(hijmk) = 1
If himjk <= 200 Then had(himjk) = 1
If himjmk <= 200 Then had(himjmk) = 1
Next
Next
Next
For i = 1 To 200
If had(i) = 0 Then Exit For
Next
tot = i - 1
If tot > highTot Then
highTot = tot
Cls
Print h(1), h(2), h(3)
Print highTot
For i = 1 To 7
bestH(i) = h(i)
Print h(i);
Next
Print
End If
DoEvents
Else
which = which + 1
For i = Int(lbs * 1.5) To lbs * 3.4
If i <= 200 Then
try i
End If
Next
which = which - 1
End If
End Sub
Private Sub cmdStart_Click()
which = 1
For i = 1 To 4
try i
Next
End Sub
Early exploration with a QB program with wider ranges of possibilities indicated that good results could come with each successive weight being between 1.5 and 3.4 times the weight of the previous one, and that was incorporated into this search, as was a limit on the first, to be 1 through 4.
At the end, the set 1, 3, 9, 14, 40, 64, 97 allows the weighing to continue through 114 as the maximum age.
|
Posted by Charlie
on 2006-11-14 23:42:00 |