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

 Plus and Minus (Posted on 2003-02-05)
Frame at least 8 different equations by inserting plus and minus signs only into 1,2,3,4,5,6,7,8,9; to give a total of 100.

For example: 123 - 45 - 67 + 89 = 100

(The numbers must stay in the normal ascending order from 1 to 9).

 See The Solution Submitted by Ravi Raja Rating: 2.5000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 re: solution Comment 6 of 6 |
(In reply to solution by Charlie)

The program for finding these is as follows. (Of course after this, the output file had to be sorted and then run through another program summarizing duplicate totals with (## others).):
DECLARE SUB setIt (noOps#, thisOp#)
DEFDBL A-Z
DIM SHARED s\$
DIM SHARED posn(9)
DIM SHARED t\$(9)

OPEN "tendig.txt" FOR OUTPUT AS #1
s\$ = "0123456789"

FOR noOps = 1 TO 9
setIt noOps, 1
NEXT
CLOSE
END

SUB setIt (noOps, thisOp)
IF thisOp = 1 THEN strt = 2: ELSE strt = posn(thisOp - 1) + 1
ending = 10 - noOps + thisOp
FOR posit = strt TO ending
posn(thisOp) = posit
t\$(thisOp) = "+"
GOSUB tryIt
t\$(thisOp) = "-"
GOSUB tryIt
NEXT
EXIT SUB

tryIt:
IF thisOp = noOps THEN
tot = VAL(LEFT\$(s\$, posn(1) - 1))
PRINT #1, LEFT\$(s\$, posn(1) - 1);
FOR j = 2 TO noOps
v = VAL(MID\$(s\$, posn(j - 1), posn(j) - posn(j - 1)))
IF t\$(j - 1) = "+" THEN tot = tot + v: ELSE tot = tot - v
PRINT #1, t\$(j - 1); v;
NEXT
v = VAL(MID\$(s\$, posn(noOps)))
IF t\$(noOps) = "+" THEN tot = tot + v: ELSE tot = tot - v
PRINT #1, t\$(noOps); v; "="; tot
ELSE
setIt noOps, thisOp + 1
END IF
RETURN
END SUB

 Posted by Charlie on 2003-06-05 10:14:26

 Search: Search body:
Forums (0)