(In reply to
re(4): best I can do -- computer solutions involving division by Charlie)
The solutions were filtered from the output of:
10 V$="0123456789":H$=V$
11 kill "2011b.txt":open "2011b.txt" for output as #2
15 repeat
20 gosub *Permute(&V$)
30 for pos1=1 to 8
40 n1s=left(v$,pos1):rest1s=mid(v$,pos1+1,*)
41 if left(n1s,1)="0" then goto 770
50 n1=val(n1s)
55 for pos2=1 to len(rest1s)
56 n2s=left(rest1s,pos2):n3s=mid(rest1s,pos2+1,*)
57 if left(n2s,1)="0" then goto 280
58 if left(n3s,1)="0" then goto 280
59 n2=val(n2s):n3=val(n3s):flag=""
60 for op1=1 to 4
65 result=0
70 if op1=1 then
80 :result=n1+n2
90 :elseif op1=2 then
100 :result=n1-n2
110 :elseif op1=3 then
120 :result=n1*n2
130 :elseif op1=4 and n2<>0 then
140 :result=n1//n2
141 :elseif op1=4 and n2=0 then
142 :flag="bad"
150 :endif
160 for op2=1 to 4
170 if op2=1 then
180 :result2=result+n3:if result2 = 2011 then print n1;mid("+-*/",op1);n2;mid("+-*/",op2);n3;flag:print#2, n1;mid("+-*/",op1);n2;mid("+-*/",op2);n3;flag:endif
190 :elseif op2=2 then
200 :result2=result-n3:if result2 = 2011 then print n1;mid("+-*/",op1);n2;mid("+-*/",op2);n3;flag:print#2, n1;mid("+-*/",op1);n2;mid("+-*/",op2);n3;flag:endif
210 :elseif op2=3 then
220 :result2=result*n3:if result2 = 2011 then print n1;mid("+-*/",op1);n2;mid("+-*/",op2);n3;flag:print#2, n1;mid("+-*/",op1);n2;mid("+-*/",op2);n3;flag:endif
230 :elseif op2=4 and n3<>0 then
240 :result2=result//n3:if result2 = 2011 then print n1;mid("+-*/",op1);n2;mid("+-*/",op2);n3;flag:print#2, n1;mid("+-*/",op1);n2;mid("+-*/",op2);n3;flag:endif
241 :elseif op2=4 and n3=0 then
242 :flag="bad"
250 :endif
260 next op2
270 next op1
280 next pos2
770 next pos1
785 until V$=H$
790 close 2:end
800
Edited on January 1, 2011, 2:47 pm
|
Posted by Charlie
on 2011-01-01 14:47:25 |