我愿意和你一起研究研究,你有时间给我研究研究这段代码吧!
on (release) {
if (a<0 || b<0 || c<0 || d<0 || isNan(a) || isNan(b) || isNan(c) || isNan(d)) {
_root.result.result = "请输入正确的数字";
} else {
a = Number(a);
b = Number(b);
c = Number(c);
d = Number(d);
var arr = new Array();
arr[0] = new Array(a, b, c, d);
arr[1] = new Array(a, b, d, c);
arr[2] = new Array(a, c, b, d);
arr[3] = new Array(a, c, d, b);
arr[4] = new Array(a, d, b, c);
arr[5] = new Array(a, d, c, b);
arr[6] = new Array(b, a, c, d);
arr[7] = new Array(b, a, d, c);
arr[8] = new Array(b, c, a, d);
arr[9] = new Array(b, c, d, a);
arr[10] = new Array(b, d, a, c);
arr[11] = new Array(b, d, c, a);
arr[12] = new Array(c, a, b, d);
arr[13] = new Array(c, a, d, b);
arr[14] = new Array(c, b, a, d);
arr[15] = new Array(c, b, d, a);
arr[16] = new Array(c, d, a, b);
arr[17] = new Array(c, d, b, a);
arr[18] = new Array(d, a, b, c);
arr[19] = new Array(d, a, c, b);
arr[20] = new Array(d, b, a, c);
arr[21] = new Array(d, b, c, a);
arr[22] = new Array(d, c, a, b);
arr[23] = new Array(d, c, b, a);
var arr_b = new Array(4);
var flag = false;
for (i=0; i<24; i++) {
arr_b[0] = arr[i][0];
arr_b[1] = arr[i][1];
arr_b[2] = arr[i][2];
arr_b[3] = arr[i][3];
for (x=0; x<6; x++) {
for (y=0; y<6; y++) {
for (z=0; z<6; z++) {
if (cacu(cacu(cacu(arr_b[0], arr_b[1], x), arr_b[2], y), arr_b[3], z) == 24) {
getResult(arr_b, x, y, z, 1);
flag = true;
break;
}
if (cacu(cacu(arr_b[0], arr_b[1], x), cacu(arr_b[2], arr_b[3], z), y) == 24) {
getResult(arr_b, x, y, z, 2);
flag = true;
break;
}
}
if (flag == true) {
break;
}
}
if (flag == true) {
break;
}
}
}
if (flag == false) {
_root.result.result = "不能得到结果";
}
}
function cacu(a, b, o) {
switch (o) {
case 0 :
return a+b;
case 1 :
return a-b;
case 2 :
return b-a;
case 3 :
return a*b;
case 4 :
return a/b;
default :
return b/a;
}
}
function getOpt(o) {
switch (o) {
case 0 :
return "+";
case 1 :
return "-";
case 2 :
return "-";
case 3 :
return "*";
case 4 :
return "/";
default :
return "/";
}
}
function getResult(a, x, y, z, flag) {
var str = "";
if (flag == 1) {
if (x == 2 || x == 5) {
str += a[1]+getOpt(x)+a[0];
} else {
str += a[0]+getOpt(x)+a[1];
}
/////////////////
if (y == 2) {
if (x<3) {
str = a[2]+"-("+str+"
";
} else {
str = a[2]+"-"+str;
}
} else if (y == 5) {
str = a[2]+"/("+str+"
";
} else {
if (x<3 && y>2) {
str = "("+str+"
"+getOpt(y)+a[2];
} else {
str = str+getOpt(y)+a[2];
}
}
////////////////////////
if (z == 2) {
if (x<3 || y<3) {
str = a[3]+"-"+str;
}
} else if (z == 5) {
str = a[3]+"/("+str+"
";
} else {
if ((x<3 || y<3) && z>2) {
str = "("+str+"
"+getOpt(z)+a[3];
} else {
str = str+getOpt(z)+a[3];
}
}
} else if (flag == 2) {
if (x == 2 || x == 5) {
str += a[1]+getOpt(x)+a[0];
} else {
str += a[0]+getOpt(x)+a[1];
}
var str2 = "";
if (z == 2 || z == 5) {
str2 += a[3]+getOpt(z)+a[2];
} else {
str2 += a[2]+getOpt(z)+a[3];
}
if (y>2) {
if (x<3) {
str = "("+str+"
";
}
if (z<3) {
str2 = "("+str2+"
";
}
}
if (y == 2 || y == 5) {
str = str2+getOpt(y)+str;
} else {
str = str+getOpt(y)+str2;
}
}
_root.result.result = str+"=24";
}
}