<option value = 5>5 <option value = 6>6 <option value = 7>7 <option value = 8>8 <option value = 9>9 </select>
<select name="n2"> <option selected value = 0>0 <option value = 1>1 <option value = 2>2 <option value = 3>3 <option value = 4>4 <option value = 5>5 <option value = 6>6 <option value = 7>7 <option value = 8>8 <option value = 9>9 </select>
<select name="n3"> <option selected value = 0>0 <option value = 1>1 <option value = 2>2 <option value = 3>3 <option value = 4>4 <option value = 5>5 <option value = 6>6 <option value = 7>7 <option value = 8>8
<select name="n4"> <option selected value = 0>0 <option value = 1>1 <option value = 2>2 <option value = 3>3 <option value = 4>4 <option value = 5>5 <option value = 6>6 <option value = 7>7 <option value = 8>8 <option value = 9>9 </select>
<input type="button" value = "計算" onClick = "calcAndPrint();">
<option value = 5>5 <option value = 6>6 <option value = 7>7 <option value = 8>8 <option value = 9>9 </select>
<select name="n2"> <option selected value = 0>0 <option value = 1>1 <option value = 2>2 <option value = 3>3 <option value = 4>4 <option value = 5>5 <option value = 6>6 <option value = 7>7 <option value = 8>8 <option value = 9>9 </select>
<select name="n3"> <option selected value = 0>0 <option value = 1>1 <option value = 2>2 <option value = 3>3 <option value = 4>4 <option value = 5>5 <option value = 6>6 <option value = 7>7 <option value = 8>8
<option value = 5>5 <option value = 6>6 <option value = 7>7 <option value = 8>8 <option value = 9>9 </select>
<select name="n2"> <option selected value = 0>0 <option value = 1>1 <option value = 2>2 <option value = 3>3 <option value = 4>4 <option value = 5>5 <option value = 6>6 <option value = 7>7 <option value = 8>8 <option value = 9>9 </select>
<select name="n3"> <option selected value = 0>0 <option value = 1>1 <option value = 2>2 <option value = 3>3 <option value = 4>4 <option value = 5>5 <option value = 6>6 <option value = 7>7 <option value = 8>8
ival=inputbox("4桁の数字入れれ") if len(ival)<>4 then wscript.quit for q=0 to 4*4*4-1 op=q oval=clng(mid(ival,1,1)) for r=2 to 4 select case op mod 4 case 0:oval=oval+clng(mid(ival,r,1)) case 1:oval=oval-clng(mid(ival,r,1)) case 2:oval=oval*clng(mid(ival,r,1)) case 3:oval=oval/clng(mid(ival,r,1)) end select op=op\4 next
if oval=10 then op=q out=mid(ival,1,1) for r=2 to 4 select case op mod 4 case 0:out=out&"+"&mid(ival,r,1) case 1:out=out&"-"&mid(ival,r,1) case 2:out=out&"*"&mid(ival,r,1) case 3:out=out&"/"&mid(ival,r,1) end select op=op\4 next msgbox out,4096,"でけた" exit for end if next
dim ival() istr=inputbox("4桁の数字入れれ") if len(istr)=4 then redim ival(3) for i=0 to 3 ival(i)=cint(mid(istr,i+1,1)) next
for i=0 to 3 for j=0 to 3 for k=0 to 3 for l=0 to 1 if l=1 then ival(0)=-ival(0) for x=0 to 2 for y=0 to 1 ans=val(ival(x),i,ival(x+1)) out=val2(ival(x),i,ival(x+1)) select case x case 0 select case y case 0 ans=val(val(ans,j,ival(2)),k,ival(3)) out=val2(val2(out,j,ival(2)),k,ival(3)) case 1 ans=val(ans,k,val(ival(2),j,ival(3))) out=val2(out,k,val2(ival(2),j,ival(3))) end select
case 1 select case y case 0 ans=val(val(ival(0),j,ans),k,ival(3)) out=val2(val2(ival(0),j,out),k,ival(3)) case 1 ans=val(ival(0),k,val(ans,j,ival(3))) out=val2(ival(0),k,val2(out,j,ival(3))) end select case 2 select case y case 0 'やらない case 1 ans=val(ival(0),k,val(ival(1),j,ans)) out=val2(ival(0),k,val2(ival(1),j,out)) end select end select if ans=10 then if instr(replace(replace(out2,"(",""),")",""),replace(
replace(out,"(",""),")",""))=0 then out2=out2&vbcrlf&" |"&out end if end if out=""
next next next next next next if len(out2)<>0 then msgbox " / ̄ ̄ ̄ ̄"&vbcrlf&"< でけた"&out2&vbcrlf&" \____",vbcritical+4096,"10作る" else msgbox " / ̄ ̄ ̄ ̄"&vbcrlf&"< できない"&vbcrlf&" \____",vbcritical+4096,"10作る" end if end if function val(a,op,b) select case op case 0:val=a+b case 1:val=a-b case 2:val=a*b case 3:if b=0 then val=-100 else val=a/b end select end function function val2(a,op,b) select case op case 0:val2=a&"+"&b case 1:val2=a&"-"&b case 2:val2=a&"*"&b case 3:val2=a&"/"&b end select val2="("&val2&")" end function
A op1 B op2 C op3 D (A op1 B) op2 C op3 D A op1 (B op2 C) op3 D A op1 B op2 (C op3 D) (A op1 B) op2 (C op3 D) (A op1 B op2 C) op3 D (A op1 (B op2 C)) op3 D ((A op1 B) op2 C) op3 D A op1 (B op2 C op3 D) A op1 (B op2 (C op3 D)) A op1 ((B op2 C) op3 D)
public class TenFinder { public static final String OP_ADD = "+"; public static final String OP_SUB = "-"; public static final String OP_MUL = "*"; public static final String OP_DIV = "/"; public static final String[] OPS = {OP_ADD, OP_SUB, OP_MUL, OP_DIV};
public static void main(String[] args) { for (int i = 0; i < 10000; i++) { int a = i / 1000; int b = (i - (a * 1000)) / 100; int c = (i - (a * 1000) - (b * 100)) / 10; int d = (i - (a * 1000) - (b * 100) - (c * 10)) / 1; System.out.println(a + " " + b + " " + c + " " + d + "------------------------"); search(a, b, c, d); } }
private static void search(int a, int b, int c, int d) { for (int x = 0; x < OPS.length; x++) for (int y = 0; y < OPS.length; y++) for (int z = 0; z < OPS.length; z++) calculate(a, OPS[x], b, OPS[y], c, OPS[z], d); }
private static void calculate(int a, String x, int b, String y, int c, String z, int d) { calculateWithPatern1(a, x, b, y, c, z, d); calculateWithPatern2(a, x, b, y, c, z, d); calculateWithPatern3(a, x, b, y, c, z, d); calculateWithPatern4(a, x, b, y, c, z, d); calculateWithPatern5(a, x, b, y, c, z, d); }
//(A op B) op (C op D) private static void calculateWithPatern1(int a, String x, int b, String y, int c, String z, int d) { try { int result = simpleCalc(simpleCalc(a, x, b), y, simpleCalc(c, z, d)); if (result == 10) System.out.println("(" + a + x + b + ")" + y + "(" + c + z + d + ") = 10"); } catch (ArithmeticException ex) { return; } }
//((A op B) op C) op D private static void calculateWithPatern2(int a, String x, int b, String y, int c, String z, int d) { try { int result = simpleCalc(simpleCalc(simpleCalc(a, x, b), y, c), z, d); if (result == 10) System.out.println("((" + a + x + b + ")" + y + c + ")" + z + d + " = 10"); } catch (ArithmeticException ex) { return; } }
//(A op (B op C)) op D private static void calculateWithPatern3(int a, String x, int b, String y, int c, String z, int d) { try { int result = simpleCalc(simpleCalc(a, x, simpleCalc(b, y, c)), z, d); if (result == 10) System.out.println("(" + a + x + "(" + b + y + c + "))" + z + d + " = 10"); } catch (ArithmeticException ex) { return; } }
//A op ((B op C) op D) private static void calculateWithPatern4(int a, String x, int b, String y, int c, String z, int d) { try { int result = simpleCalc(a, x, simpleCalc(simpleCalc(b, y, c), z, d)); if (result == 10) System.out.println(a + x + "((" + b + y + c + ")" + z + d + ") = 10"); } catch (ArithmeticException ex) { return; } }
//A op (B op (C op D)) private static void calculateWithPatern5(int a, String x, int b, String y, int c, String z, int d) { try { int result = simpleCalc(a, x, simpleCalc(b, y, simpleCalc(c, z, d))); if (result == 10) System.out.println(a + x + "(" + b + y + "(" + c + z + d + ")) = 10"); } catch (ArithmeticException ex) { return; } }
private static int simpleCalc(int m, String op, int n) throws ArithmeticException { if (op.equals(OP_ADD)) return m + n; else if (op.equals(OP_SUB)) return m - n; else if (op.equals(OP_MUL)) return m * n; else { if (n == 0) throw new ArithmeticException(); if ((m % n) != 0) throw new ArithmeticException(); return m / n; } } }