A set of five coins contains two that weigh 31g, two that weigh 33g, and one that weighs 32g. Using a balance scale just two times positively identify the weight of at least one coin.
Weighing 1: Weigh one against another.
Weighing 1 result: equal weight:
then weigh both against two others
If the others are heavier in total the first two weights are each 31 g.
If the others are lighter in total the first two weights are each 33 g.
The second weighing will never be equality.
Weighing 1 result: one is heavier:
The situation could be either 33g vs 32g, 33g vs 31g or 32g vs 31g.
Weigh both against two others
1st 2nd 2nd result
33 v 32 33+32 v 33+31 left heavy
33 v 32 33+32 v 31+31 left heavy
33 v 31 33+31 v 33+31 equal
33 v 31 33+31 v 33+32 right heavy
33 v 31 33+31 v 32+31 left heavy
32 v 31 32+31 v 33+33 right heavy
32 v 31 32+31 v 33+31 right heavy
By result of 2nd weighing:
left heavy --> heavier of first weighing is 33 g.
equal weight --> heavier of first weighing is 33 g and lighter is 31 g.
right heavy --> lighter of first weighing is 31 g.
Using the rules on all possible permutations of the given weights results in the following conclusions, when first weighing A on the left against B on the right, and then A and B together on the left against C and D on the right.
A B C D E which side is conclusion
heavier
w1 w2
33 33 32 31 31 =l A & B 33g
31 31 32 33 33 =r A & B 31g
31 31 33 32 33 =r A & B 31g
31 31 33 33 32 =r A & B 31g
31 32 31 33 33 rr A 31g
31 32 33 31 33 rr A 31g
31 32 33 33 31 rr A 31g
31 33 31 32 33 rl B 33g
31 33 31 33 32 r= A 31g B 33g
31 33 32 31 33 rl B 33g
31 33 32 33 31 rr A 31g
31 33 33 31 32 r= A 31g B 33g
31 33 33 32 31 rr A 31g
32 31 31 33 33 lr B 31g
32 31 33 31 33 lr B 31g
32 31 33 33 31 lr B 31g
32 33 31 31 33 rl B 33g
32 33 31 33 31 rl B 33g
32 33 33 31 31 rl B 33g
33 31 31 32 33 ll A 33g
33 31 31 33 32 l= A 33g & B 31g
33 31 32 31 33 ll A 33g
33 31 32 33 31 lr B 31g
33 31 33 31 32 l= A 33g & B 31g
33 31 33 32 31 lr B 31g
33 32 31 31 33 ll A 33g
33 32 31 33 31 ll A 33g
33 32 33 31 31 ll A 33g
33 33 31 31 32 =l A & B 33g
33 33 31 32 31 =l A & B 33g
and the "never" condition, ==, indeed never occurs.
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
s$ = Chr$(33) + Chr$(33) + Chr$(32) + Chr$(31) + Chr$(31)
h$ = s
Do
For i = 1 To 5
Text1.Text = Text1.Text & Str(Asc(Mid(s, i, 1)))
Next
If Left(s, 1) < Mid(s, 2, 1) Then e$ = "r"
If Left(s, 1) = Mid(s, 2, 1) Then e$ = "="
If Left(s, 1) > Mid(s, 2, 1) Then e$ = "l"
If Asc(Left(s, 1)) + Asc(Mid(s, 2, 1)) < Asc(Mid(s, 3, 1)) + Asc(Mid(s, 4, 1)) Then e$ = e$ + "r"
If Asc(Left(s, 1)) + Asc(Mid(s, 2, 1)) = Asc(Mid(s, 3, 1)) + Asc(Mid(s, 4, 1)) Then e$ = e$ + "="
If Asc(Left(s, 1)) + Asc(Mid(s, 2, 1)) > Asc(Mid(s, 3, 1)) + Asc(Mid(s, 4, 1)) Then e$ = e$ + "l"
Text1.Text = Text1.Text & " " & e & " "
Select Case e
Case "rr"
Text1.Text = Text1.Text & "A 31g"
Case "r="
Text1.Text = Text1.Text & "A 31g B 33g"
Case "rl"
Text1.Text = Text1.Text & "B 33g"
Case "=r"
Text1.Text = Text1.Text & "A & B 31g"
Case "=="
Text1.Text = Text1.Text & "never"
Case "=l"
Text1.Text = Text1.Text & "A & B 33g"
Case "lr"
Text1.Text = Text1.Text & "B 31g"
Case "l="
Text1.Text = Text1.Text & "A 33g & B 31g"
Case "ll"
Text1.Text = Text1.Text & "A 33g"
End Select
Text1.Text = Text1.Text & crlf
permute s$
Loop Until s = h
Text1.Text = Text1.Text & crlf & " done"
End Sub
Sub permute(a$)
x$ = ""
For i = Len(a$) To 1 Step -1
l$ = x$
x$ = Mid$(a$, i, 1)
If x$ < l$ Then Exit For
Next
If i = 0 Then
For j = 1 To Len(a$) \ 2
x$ = Mid$(a$, j, 1)
Mid$(a$, j, 1) = Mid$(a$, Len(a$) - j + 1, 1)
Mid$(a$, Len(a$) - j + 1, 1) = x$
Next
Else
For j = Len(a$) To i + 1 Step -1
If Mid$(a$, j, 1) > x$ Then Exit For
Next
Mid$(a$, i, 1) = Mid$(a$, j, 1)
Mid$(a$, j, 1) = x$
For j = 1 To (Len(a$) - i) \ 2
x$ = Mid$(a$, i + j, 1)
Mid$(a$, i + j, 1) = Mid$(a$, Len(a$) - j + 1, 1)
Mid$(a$, Len(a$) - j + 1, 1) = x$
Next
End If
End Sub
|
Posted by Charlie
on 2016-01-04 10:54:12 |