All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 6 coins (Posted on 2016-01-13)
There are 6 coins weighing 1, 2, 3, 4, 5 and 6 grams that look the same, except for their labels. The labels are supposed to display the weights of the coins.

How can you determine whether all the labels are correct,
using the balance scale only twice?

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solution | Comment 5 of 10 |
1 13 5 125 36
123456

Weigh those labeled 1 and 3 against that labeled 5. The RHS should be heavy if it's accurately labeled.

Then weigh those labeled 1, 2 and 5 against those labeled 3 and 6. Again the RHS should go down.

If it passes these tests the labelling is good.

Program modified to allow unequal weights, placing any given weight on either the right, left or neither pan, twice.  The program is inefficient, in finding basically the same solution eight times, with pans reversed or weighings reversed, so run time was slowed (but development time was saved).

DefDbl A-Z
Dim crlf\$, combs(21, 10) As String, ncombs(21), how\$(720)

Form1.Visible = True

Text1.Text = ""
crlf = Chr\$(13) + Chr\$(10)

For n1 = 0 To 1
For n2 = 0 To 1
For n3 = 0 To 1
For n4 = 0 To 1
For n5 = 0 To 1
For n6 = 0 To 1
tot = n1 + 2 * n2 + 3 * n3 + 4 * n4 + 5 * n5 + 6 * n6
cm\$ = ""
If n1 Then cm = cm + "1"
If n2 Then cm = cm + "2"
If n3 Then cm = cm + "3"
If n4 Then cm = cm + "4"
If n5 Then cm = cm + "5"
If n6 Then cm = cm + "6"
ncombs(tot) = ncombs(tot) + 1
combs(tot, ncombs(tot)) = cm
Next
Next
Next
Next
Next
Next

For tot = 1 To 21
For i = 1 To ncombs(tot)
Text1.Text = Text1.Text & mform(tot, "##0") & "  " & combs(tot, i) & crlf
Next
Text1.Text = Text1.Text & crlf
Next

minways = 9999
For n1a = 0 To 2
Text1.Text = Text1.Text & n1a & crlf
For n2a = 0 To 2
For n3a = 0 To 2
For n4a = 0 To 2
For n5a = 0 To 2
For n6a = 0 To 2
For n1b = 0 To 2
For n2b = 0 To 2
For n3b = 0 To 2
For n4b = 0 To 2
For n5b = 0 To 2
For n6b = 0 To 2

lhs1\$ = "": rhs1\$ = "": lhs2\$ = "": rhs2\$ = ""
exp1l = 0: exp2l = 0: exp1r = 0: exp2r = 0
Select Case n1a
Case 1: lhs1 = lhs1 + "1": exp1l = exp1l + 1
Case 2: rhs1 = rhs1 + "1": exp1r = exp1r + 1
End Select
Select Case n2a
Case 1: lhs1 = lhs1 + "2": exp1l = exp1l + 2
Case 2: rhs1 = rhs1 + "2": exp1r = exp1r + 2
End Select
Select Case n3a
Case 1: lhs1 = lhs1 + "3": exp1l = exp1l + 3
Case 2: rhs1 = rhs1 + "3": exp1r = exp1r + 3
End Select
Select Case n4a
Case 1: lhs1 = lhs1 + "4": exp1l = exp1l + 4
Case 2: rhs1 = rhs1 + "4": exp1r = exp1r + 4
End Select
Select Case n5a
Case 1: lhs1 = lhs1 + "5": exp1l = exp1l + 5
Case 2: rhs1 = rhs1 + "5": exp1r = exp1r + 5
End Select
Select Case n6a
Case 1: lhs1 = lhs1 + "6": exp1l = exp1l + 6
Case 2: rhs1 = rhs1 + "6": exp1r = exp1r + 6
End Select

Select Case n1b
Case 1: lhs2 = lhs2 + "1": exp2l = exp2l + 1
Case 2: rhs2 = rhs2 + "1": exp2r = exp2r + 1
End Select
Select Case n2b
Case 1: lhs2 = lhs2 + "2": exp2l = exp2l + 2
Case 2: rhs2 = rhs2 + "2": exp2r = exp2r + 2
End Select
Select Case n3b
Case 1: lhs2 = lhs2 + "3": exp2l = exp2l + 3
Case 2: rhs2 = rhs2 + "3": exp2r = exp2r + 3
End Select
Select Case n4b
Case 1: lhs2 = lhs2 + "4": exp2l = exp2l + 4
Case 2: rhs2 = rhs2 + "4": exp2r = exp2r + 4
End Select
Select Case n5b
Case 1: lhs2 = lhs2 + "5": exp2l = exp2l + 5
Case 2: rhs2 = rhs2 + "5": exp2r = exp2r + 5
End Select
Select Case n6b
Case 1: lhs2 = lhs2 + "6": exp2l = exp2l + 6
Case 2: rhs2 = rhs2 + "6": exp2r = exp2r + 6
End Select

rhsh1 = Sgn(exp1r - exp1l)
rhsh2 = Sgn(exp2r - exp2l)

ws = ways(lhs1, rhs1, lhs2, rhs2, rhsh1, rhsh2)
If ws < minways And ws > 0 Or ws = 1 Then
minways = ws
Text1.Text = Text1.Text & minways & " " & lhs1 & " " & rhs1 & " " & lhs2 & " " & rhs2 & crlf
If minways < 10 Then
For j = 1 To minways
Text1.Text = Text1.Text & how(j) & crlf
Next
Text1.Text = Text1.Text & crlf
End If
End If
If ws = 1 Then
Text1.Text = Text1.Text & lhs1 & " " & rhs1 & " " & lhs2 & " " & rhs2 & crlf

End If

Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next

Text1.Text = Text1.Text & crlf & minways & " done"

Exit Sub

coins\$ = "123456": h\$ = coins
Do
DoEvents
lhst1 = Val(Mid(coins, 1, 1)) + Val(Mid(coins, 2, 1)) + Val(Mid(coins, 4, 1))
rhst1 = Val(Mid(coins, 5, 1)) + Val(Mid(coins, 2, 1))
lhst2 = Val(Mid(coins, 1, 1)) + Val(Mid(coins, 6, 1))
rhst2 = Val(Mid(coins, 3, 1)) + Val(Mid(coins, 4, 1))
If lhst1 = rhst1 And lhst2 = rhst2 Then
Text1.Text = Text1.Text & coins & crlf
End If
permute coins
Loop Until coins = h

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

Function ways(a\$, b\$, c\$, d\$, rhi1, rhi2)
w = 0
coins\$ = "123456": h\$ = coins
Do
DoEvents
lhst1 = 0
For i = 1 To Len(a)
lhst1 = lhst1 + Val(Mid(coins, Val(Mid(a, i, 1)), 1))
Next
rhst1 = 0
For i = 1 To Len(b)
rhst1 = rhst1 + Val(Mid(coins, Val(Mid(b, i, 1)), 1))
Next
lhst2 = 0
For i = 1 To Len(c)
lhst2 = lhst2 + Val(Mid(coins, Val(Mid(c, i, 1)), 1))
Next
rhst2 = 0
For i = 1 To Len(d)
rhst2 = rhst2 + Val(Mid(coins, Val(Mid(d, i, 1)), 1))
Next
If Sgn(rhst1 - lhst1) = rhi1 And Sgn(rhst2 - lhst2) = rhi2 Then
w = w + 1
how\$(w) = coins\$
End If
permute coins
Loop Until coins = h
ways = w
End Function

verification via

lhs1\$ = "13": rhs1\$ = "5"
lhs2\$ = "125": rhs2\$ = "36"
rhsh1 = 1: rhsh2 = 1
ws = ways(lhs1, rhs1, lhs2, rhs2, rhsh1, rhsh2)

resulting pan dips show only 123456 results in R R.

123456 R R
123465 R L
123546 = R
123564 R L
123645 = R
123654 R L
124356 = R
124365 R =
124536 L R
124563 R L
124635 L R
124653 = L
125346 L R
125364 = =
125436 L R
125463 = L
125634 L R
125643 L R
126345 L R
126354 L R
126435 L R
126453 L R
126534 L R
126543 L R
132456 R L
132465 R L
132546 R =
132564 R L
132645 R L
132654 R L
134256 = R
134265 R L
134526 L R
134562 R L
134625 L R
134652 = L
135246 L R
135264 = L
135426 L R
135462 = L
135624 L R
135642 L L
136245 L R
136254 L R
136425 L R
136452 L L
136524 L R
136542 L =
142356 R L
142365 R L
142536 = =
142563 R L
142635 = L
142653 R L
143256 R L
143265 R L
143526 L R
143562 R L
143625 L R
143652 R L
145236 L R
145263 = L
145326 L R
145362 = L
145623 L R
145632 L L
146235 L R
146253 L L
146325 L R
146352 L L
146523 L R
146532 L =
152346 R L
152364 R L
152436 = L
152463 R L
152634 = L
152643 R L
153246 = L
153264 R L
153426 L R
153462 R L
153624 L L
153642 = L
154236 L R
154263 R L
154326 L R
154362 R L
154623 L L
154632 L L
156234 L R
156243 L L
156324 L R
156342 L L
156423 L R
156432 L L
162345 R L
162354 R L
162435 = L
162453 R L
162534 = L
162543 R L
163245 = L
163254 R L
163425 L L
163452 R L
163524 L L
163542 = L
164235 L L
164253 = L
164325 L =
164352 = L
164523 L L
164532 L L
165234 L L
165243 L L
165324 L =
165342 L L
165423 L L
165432 L L
213456 = R
213465 R L
213546 L R
213564 R L
213645 L R
213654 = L
214356 L R
214365 = =
214536 L R
214563 = L
214635 L R
214653 L L
215346 L R
215364 L =
215436 L R
215463 L L
215634 L R
215643 L R
216345 L R
216354 L R
216435 L R
216453 L R
216534 L R
216543 L R
231456 R L
231465 R L
231546 R L
231564 R L
231645 R L
231654 R L
234156 L =
234165 = L
234516 L R
234561 = L
234615 L R
234651 L L
235146 L R
235164 L L
235416 L R
235461 L L
235614 L R
235641 L L
236145 L R
236154 L =
236415 L R
236451 L L
236514 L R
236541 L L
241356 R L
241365 R L
241536 = L
241563 R L
241635 = L
241653 R L
243156 = L
243165 R L
243516 L R
243561 R L
243615 L R
243651 = L
245136 L R
245163 L L
245316 L R
245361 L L
245613 L R
245631 L L
246135 L R
246153 L L
246315 L R
246351 L L
246513 L R
246531 L L
251346 R L
251364 R L
251436 = L
251463 R L
251634 = L
251643 R L
253146 L L
253164 R L
253416 L R
253461 R L
253614 L L
253641 L L
254136 L =
254163 = L
254316 L R
254361 = L
254613 L L
254631 L L
256134 L =
256143 L L
256314 L R
256341 L L
256413 L R
256431 L L
261345 R L
261354 R L
261435 = L
261453 R L
261534 = L
261543 R L
263145 L L
263154 = L
263415 L L
263451 = L
263514 L L
263541 L L
264135 L L
264153 L L
264315 L =
264351 L L
264513 L L
264531 L L
265134 L L
265143 L L
265314 L =
265341 L L
265413 L L
265431 L L
312456 = L
312465 R L
312546 L =
312564 R L
312645 L L
312654 = L
314256 L R
314265 L L
314526 L R
314562 L L
314625 L R
314652 L L
315246 L R
315264 L L
315426 L R
315462 L L
315624 L R
315642 L L
316245 L R
316254 L R
316425 L R
316452 L L
316524 L R
316542 L =
321456 R L
321465 R L
321546 = L
321564 R L
321645 = L
321654 R L
324156 L =
324165 L L
324516 L R
324561 L L
324615 L R
324651 L L
325146 L R
325164 L L
325416 L R
325461 L L
325614 L R
325641 L L
326145 L R
326154 L =
326415 L R
326451 L L
326514 L R
326541 L L
341256 R L
341265 R L
341526 L L
341562 R L
341625 L L
341652 R L
342156 = L
342165 R L
342516 L =
342561 R L
342615 L L
342651 = L
345126 L R
345162 L L
345216 L R
345261 L L
345612 L L
345621 L L
346125 L R
346152 L L
346215 L R
346251 L L
346512 L =
346521 L L
351246 = L
351264 R L
351426 L L
351462 R L
351624 L L
351642 = L
352146 L L
352164 R L
352416 L L
352461 R L
352614 L L
352641 L L
354126 L =
354162 L L
354216 L R
354261 L L
354612 L L
354621 L L
356124 L =
356142 L L
356214 L R
356241 L L
356412 L L
356421 L L
361245 = L
361254 R L
361425 L L
361452 R L
361524 L L
361542 = L
362145 L L
362154 = L
362415 L L
362451 = L
362514 L L
362541 L L
364125 L L
364152 L L
364215 L L
364251 L L
364512 L L
364521 L L
365124 L L
365142 L L
365214 L L
365241 L L
365412 L L
365421 L L
412356 L L
412365 = L
412536 L =
412563 = L
412635 L L
412653 L L
413256 L L
413265 L L
413526 L R
413562 L L
413625 L R
413652 L L
415236 L R
415263 L L
415326 L R
415362 L L
415623 L R
415632 L L
416235 L R
416253 L L
416325 L R
416352 L L
416523 L R
416532 L =
421356 = L
421365 R L
421536 L L
421563 R L
421635 L L
421653 = L
423156 L L
423165 L L
423516 L R
423561 L L
423615 L R
423651 L L
425136 L R
425163 L L
425316 L R
425361 L L
425613 L R
425631 L L
426135 L R
426153 L L
426315 L R
426351 L L
426513 L R
426531 L L
431256 = L
431265 R L
431526 L L
431562 R L
431625 L L
431652 = L
432156 L L
432165 = L
432516 L =
432561 = L
432615 L L
432651 L L
435126 L R
435162 L L
435216 L R
435261 L L
435612 L L
435621 L L
436125 L R
436152 L L
436215 L R
436251 L L
436512 L =
436521 L L
451236 L L
451263 R L
451326 L L
451362 R L
451623 L L
451632 L L
452136 L L
452163 = L
452316 L L
452361 = L
452613 L L
452631 L L
453126 L L
453162 L L
453216 L L
453261 L L
453612 L L
453621 L L
456123 L L
456132 L L
456213 L L
456231 L L
456312 L L
456321 L L
461235 L L
461253 = L
461325 L L
461352 = L
461523 L L
461532 L L
462135 L L
462153 L L
462315 L L
462351 L L
462513 L L
462531 L L
463125 L L
463152 L L
463215 L L
463251 L L
463512 L L
463521 L L
465123 L L
465132 L L
465213 L L
465231 L L
465312 L L
465321 L L
512346 L L
512364 L L
512436 L L
512463 L L
512634 L L
512643 L L
513246 L L
513264 L L
513426 L R
513462 L L
513624 L L
513642 L L
514236 L R
514263 L L
514326 L R
514362 L L
514623 L L
514632 L L
516234 L R
516243 L L
516324 L R
516342 L L
516423 L R
516432 L L
521346 L L
521364 = L
521436 L L
521463 = L
521634 L L
521643 L L
523146 L L
523164 L L
523416 L R
523461 L L
523614 L L
523641 L L
524136 L =
524163 L L
524316 L R
524361 L L
524613 L L
524631 L L
526134 L =
526143 L L
526314 L R
526341 L L
526413 L R
526431 L L
531246 L L
531264 = L
531426 L L
531462 = L
531624 L L
531642 L L
532146 L L
532164 L L
532416 L L
532461 L L
532614 L L
532641 L L
534126 L =
534162 L L
534216 L R
534261 L L
534612 L L
534621 L L
536124 L =
536142 L L
536214 L R
536241 L L
536412 L L
536421 L L
541236 L L
541263 = L
541326 L L
541362 = L
541623 L L
541632 L L
542136 L L
542163 L L
542316 L L
542361 L L
542613 L L
542631 L L
543126 L L
543162 L L
543216 L L
543261 L L
543612 L L
543621 L L
546123 L L
546132 L L
546213 L L
546231 L L
546312 L L
546321 L L
561234 L L
561243 L L
561324 L L
561342 L L
561423 L L
561432 L L
562134 L L
562143 L L
562314 L L
562341 L L
562413 L L
562431 L L
563124 L L
563142 L L
563214 L L
563241 L L
563412 L L
563421 L L
564123 L L
564132 L L
564213 L L
564231 L L
564312 L L
564321 L L
612345 L L
612354 L L
612435 L L
612453 L L
612534 L L
612543 L L
613245 L L
613254 L L
613425 L L
613452 L L
613524 L L
613542 L L
614235 L L
614253 L L
614325 L =
614352 L L
614523 L L
614532 L L
615234 L L
615243 L L
615324 L =
615342 L L
615423 L L
615432 L L
621345 L L
621354 L L
621435 L L
621453 L L
621534 L L
621543 L L
623145 L L
623154 L L
623415 L L
623451 L L
623514 L L
623541 L L
624135 L L
624153 L L
624315 L =
624351 L L
624513 L L
624531 L L
625134 L L
625143 L L
625314 L =
625341 L L
625413 L L
625431 L L
631245 L L
631254 L L
631425 L L
631452 L L
631524 L L
631542 L L
632145 L L
632154 L L
632415 L L
632451 L L
632514 L L
632541 L L
634125 L L
634152 L L
634215 L L
634251 L L
634512 L L
634521 L L
635124 L L
635142 L L
635214 L L
635241 L L
635412 L L
635421 L L
641235 L L
641253 L L
641325 L L
641352 L L
641523 L L
641532 L L
642135 L L
642153 L L
642315 L L
642351 L L
642513 L L
642531 L L
643125 L L
643152 L L
643215 L L
643251 L L
643512 L L
643521 L L
645123 L L
645132 L L
645213 L L
645231 L L
645312 L L
645321 L L
651234 L L
651243 L L
651324 L L
651342 L L
651423 L L
651432 L L
652134 L L
652143 L L
652314 L L
652341 L L
652413 L L
652431 L L
653124 L L
653142 L L
653214 L L
653241 L L
653412 L L
653421 L L
654123 L L
654132 L L
654213 L L
654231 L L
654312 L L
654321 L L

 Posted by Charlie on 2016-01-13 14:32:07

 Search: Search body:
Forums (1)