The numbers and symbols below are placed onto six vertical strips of paper:
8 - 2 9 × 1
+ 1 = 5 1 5
= 9 0 2 ÷ 6
1 = 5 6 = 1
Rotate and rearrange the strips so that four valid equations appear across the rows.
Note: Consider the numbers as they appear on a digital watch; 0, 1, 2, 5 and 8 are the same when rotated 180°, while 6 and 9 rotate to each other.
(In reply to
One Solution by stan)
As stan noted, the two strips containing only numbers must come at one end or the other of the set of strips. Also, the strip with -19= must be flipped relative to the others to have the one equal sign and one operator in each row. Also, either or both of the numeric strips may be flipped independently. Additionally, the whole set may be flipped.
To find all the solutions (verify the uniqueness of the one stan found), the following program is run:
DECLARE SUB permute (a$)
DATA 8+=1,=61-,2=05,9526,*1/=,1561
allFlipped:
DATA 1=+8,-19=,50=2,9526,=/1*,1561
CLS
FOR i = 1 TO 6
READ s$(i)
NEXT
GOSUB evalPerms
s$(4) = "9256" 'reverse strip 4
GOSUB evalPerms
s$(6) = "1951" 'reverse strip 6
GOSUB evalPerms
s$(4) = "9526" 'reverse strip 4 back to original
GOSUB evalPerms
RESTORE allFlipped
PRINT
FOR i = 1 TO 6
READ s$(i)
NEXT
GOSUB evalPerms
s$(4) = "9256" 'reverse strip 4
GOSUB evalPerms
s$(6) = "1951" 'reverse strip 6
GOSUB evalPerms
s$(4) = "9526" 'reverse strip 4 back to original
GOSUB evalPerms
END
evalPerms:
order$ = "1235"
FOR ord = 1 TO 24
o2$ = "46"
FOR o1 = 1 TO 2
order1$ = LEFT$(o2$, 1) + order$ + RIGHT$(o2$, 1)
FOR row = 1 TO 4
eq$ = ""
good = 1: pCol = 0
FOR col = 1 TO 6
newCh$ = MID$(s$(VAL(MID$(order1$, col, 1))), row, 1)
IF pCol = 1 AND INSTR("+-*/=", newCh$) > 0 THEN good = 0: EXIT FOR
IF INSTR("+-*/=", newCh$) > 0 THEN pCol = 1: ELSE pCol = 0
eq$ = eq$ + newCh$
NEXT col
eq$(row) = eq$
IF good = 0 THEN EXIT FOR
num1$ = "": p = 1
DO
num1$ = num1$ + MID$(eq$, p, 1)
p = p + 1
LOOP UNTIL INSTR("+-*/=", MID$(eq$, p, 1))
op1$ = MID$(eq$, p, 1): p = p + 1: num2$ = ""
DO
num2$ = num2$ + MID$(eq$, p, 1)
p = p + 1
LOOP UNTIL INSTR("+-*/=", MID$(eq$, p, 1))
op2$ = MID$(eq$, p, 1): p = p + 1
num3$ = MID$(eq$, p)
IF op1$ = "=" THEN 'standardize so num1 rel num2 = num3
h$ = num1$
num1$ = num2$: num2$ = num3$: num3$ = h$
op1$ = op2$
END IF
SELECT CASE op1$
CASE "+"
IF VAL(num1$) + VAL(num2$) <> VAL(num3$) THEN good = 0: EXIT FOR
CASE "-"
IF VAL(num1$) - VAL(num2$) <> VAL(num3$) THEN good = 0: EXIT FOR
CASE "*"
IF VAL(num1$) * VAL(num2$) <> VAL(num3$) THEN good = 0: EXIT FOR
CASE "/"
IF VAL(num1$) / VAL(num2$) <> VAL(num3$) THEN good = 0: EXIT FOR
END SELECT
NEXT row
IF good THEN
PRINT
FOR row = 1 TO 4
PRINT eq$(row)
NEXT
END IF
o2$ = RIGHT$(o2$, 1) + LEFT$(o2$, 1)
NEXT o1
permute order$
NEXT ord
RETURN
SUB permute (a$)
DEFINT A-Z
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
It finds only
18=2*9
9+6=15
5=10/2
11-5=6
|
Posted by Charlie
on 2003-12-22 18:52:44 |