DIM ball(12), attribute$(12)      'Set up 12 balls and attributes
RANDOMIZE TIMER                   'Seed the RND function
'
begin:                            '
FOR x = 1 TO 12                   'Give each ball an initial
    ball(x) = 1                   ' weight of 1 and an initial
    attribute$(x) = " equal"      ' attribute of "equal"
NEXT x                            '
oddball = INT(RND * 12) + 1       'Pick the odd ball randomly
IF RND < .5 THEN                  'Pick the odd ball's weight:
    oddweight = .9                ' a little less
ELSE                              ' or
    oddweight = 1.1       ' a little more
END IF                    ' than the others
ball(oddball) = oddweight 'Give the odd ball its odd weight
'
'Not very elegant but functional solution from
'Jim Eccleston
'241 East 19th Street
'North Vancouver, BC
'V7L 2Z1  CANADA
'604-988-7597
'
sw1 = ball(1) + ball(2) + ball(3) ' composite weights for comparison
sw2 = ball(9) + ball(10) + ball(11)
sw3 = ball(5) + ball(6) + ball(7)
sw4 = ball(2) + ball(3) + ball(4)
sw5 = ball(10) + ball(11) + ball(12)
w1 = sw3 + ball(8): w2 = sw2 + ball(12)
w3 = sw2 + ball(5): w4 = sw1 + ball(12)
w5 = sw3 + ball(9): w6 = sw1 + ball(8)
'
'
IF w1 > w2 THEN 100       'Do 1st level weigh
IF w2 > w1 THEN 200
                          'Bad penny not on scale with w1 and w2
IF sw4 > sw5 THEN 40      'Do 2nd level weigh for equal 1st level
IF sw5 > sw4 THEN 60
                          'Bad penny not on scale with sw4 and sw5
                          ' - must be 1,2,3 or 4
                          'Check 1 first for overweight
                          '
IF ball(1) > ball(12) THEN id = 1: GOTO 2000
                          '
                          'Check 1 for underweight
                          '
IF ball(12) > ball(1) THEN id = 1: GOTO 1000
                          '
                          'Bad penny is overweight 2,3 or 4
                          '
40 IF ball(3) > ball(4) THEN id = 3: GOTO 2000
IF ball(4) > ball(3) THEN id = 4: GOTO 2000
        id = 2: GOTO 2000
                          'Bad penny is underweight 2,3 or 4
                          '
60 IF ball(3) > ball(4) THEN id = 4: GOTO 1000
IF ball(4) > ball(3) THEN id = 3: GOTO 1000
        id = 2: GOTO 1000
                          'Here if original left side was heavier
                          'Change weight sets and re-weigh
                          '
100 IF w3 > w4 THEN 140   '2nd level weigh for heavy left 1st weigh
IF w4 > w3 THEN 160
IF ball(7) > ball(8) THEN id = 7: GOTO 2000
IF ball(8) > ball(7) THEN id = 8: GOTO 2000
        id = 6: GOTO 2000
                          '
                          'Here if new left side is heavier
                          '
                          '
                          '3rd level weigh here
140 IF ball(5) > ball(1) THEN id = 5: GOTO 2000
IF ball(1) = ball(5) THEN id = 12: GOTO 1000
                          '
                          '
                          '3rd level weigh here
160 IF ball(10) > ball(11) THEN id = 11: GOTO 1000
IF ball(11) > ball(10) THEN id = 10: GOTO 1000
        id = 9: GOTO 1000
                          'Here if new right side is heavier
                          '
                          'change weight sets and re-weigh
                          '
200 IF w5 > w6 THEN 240   '2nd level weigh for right heavy 1st weigh
IF w6 > w5 THEN 260
IF ball(11) > ball(12) THEN id = 11: GOTO 2000
IF ball(12) > ball(11) THEN id = 12: GOTO 2000
        id = 10: GOTO 2000
                          '
                          'Here if new left side is heavier
                          '
                          '
                          '3rd level weigh here
240 IF ball(9) > ball(1) THEN id = 9: GOTO 2000
IF ball(1) = ball(9) THEN id = 8: GOTO 1000
                          '
                          'Here if new right side is heavier
                          '
                          '
                          '3rd level weigh here
260 IF ball(6) > ball(7) THEN id = 7: GOTO 1000
IF ball(7) > ball(6) THEN id = 6: GOTO 1000
        id = 5: GOTO 1000
                          ' 
                          'Print results and loop
                          '
1000 PRINT "Oddball= "; oddball; " Ball"; id; " weighed LO "; ball(id)
        GOTO begin:
'
2000 PRINT "Oddball= "; oddball; " Ball"; id; " weighed HI "; ball(id)
        GOTO begin:
'
'
'Flowchart for weighing sequence structure above follows, with balls
'represented by alpha characters A thru L. ( I was less confused! )
'
'Letters shown in the balance pans. Outcome is Left, Balanced, Right
'L suffix in letter pairs = underweight, H suffix = overweight
'
'1st Level Weighing   
'                               +------+------+
'                               | EFGH | IJKL |
'                               +------+------+
'                                      |
'                  +-------------------+---------------------+
'2nd Level         |                   |                     |
'           +------+------+      +-----+-----+        +------+------+
'           | IJKE | LABC |      | BCD | JKL |        | EFGI | HABC |
'           +------+------+      +-----+-----+        +------+------+
'            |     |     |        |    |    |          |     |     |
'3rd Level   |     |     |        |    |    |          |    /      |
'        +---+---+ | +---+---+    |    |    |    +---+---+ | +---+---+
'        | J | K | | | E | A |    |    |    |    | F | G | | | I | A |
'        +---+---+ | +---+---+    |    |    |    +---+---+ | +---+---+
'        KL IL JL  |  EH LL *     |    |    |    GL EL FL  |  IH HL  *
'                  |             /     |     \              \
'              +---+---+        /      |      \          +---+---+
'              | G | H |       /       |       \         | K | L |
'              +---+---+      /        |        \        +---+---+
'             GH  FH  HH     |         |         |       KH  JH  LH
'                     +---+---+    +---+---+    +---+---+
'                     | C | D |    | A | L |    | C | D |
'                     +---+---+    +---+---+    +---+---+
'                     CH BH DH     AH  *  AL    DL BL CL
' * = Innaplicable
'

