This Domain(Admin5.com) is for Sale:

JavaScript基础实例:如何计算24点

时间:2007-12-27  来源:不详  作者:林子

}
return st;
}

var n = new Array();//四个数字

file://接收四个输入框的数字,调用主程序
function funCount()
{
n[0] = document.forms[0].fa.value;
n[1] = document.forms[0].fb.value;
n[2] = document.forms[0].fc.value; 织梦好,好织梦


n[3] = document.forms[0].fd.value;
if ( n[0] > 0 && n[1] > 0 && n[2] > 0 && n[3] > 0 && n[0] < 14 && n[1] < 14 && n[2] < 14 && n[3] < 14 )
{
log("<font size=5><b>" n[0] ", " n[1] ", " n[2] ", " n[3] "的24点答案:</b></font><br>");
log("<input type='button' onclick='history.back(-1);' value=' 再来一次 '><br>");
funMain();
if ( counter == 0 )
{
log("没有答案!");
}
}
else
{
alert("输入错误!");
}
}

file://主程序
function funMain()
{
var m = new Array();
file://四种运算符
m[0] = " ";
m[1] = "-";
m[2] = "*";
m[3] = "/";

file://11种表达式
var exp1 = "a m1 b m2 c m3 d;";
var exp2 = "(a m1 b) m2 c m3 d;";
var exp3 = "(a m1 b m2 c) m3 d;";
var exp4 = "((a m1 b) m2 c) m3 d;"; copyright dedecms
var exp5 = "(a m1 (b m2 c)) m3 d;";
var exp6 = "a m1 (b m2 c) m3 d;";
var exp7 = "a m1 (b m2 c m3 d);";
var exp8 = "a m1 ((b m2 c) m3 d);";

织梦好,好织梦

var exp9 = "a m1 (b m2 (c m3 d));";
var exp10 = "a m1 b m2(c m3 d);";
var exp11 = "(a m1 b) m2 (c m3 d);";

var a,b,c,d;//四个数字
var m1,m2,m3;//三个运算符

for (var i=0;i<4;i )
{
a = n[i];
for (var j=0;j<4;j )
{
if ( i == j ) break;//从未选的三个数字中选择一个数字
b = n[j];
for (var x=0;x<4;x )
{
if ( j == x ) break;//从未选的两个数字中选择一个数字
c = n[x];
for (var y=0;y<4;y )
{
if ( x == y ) break;//从未选的一个数字中选择一个数字
d = n[y];

for (var ta=0;ta<4;ta )
{
m1 = m[ta];
for (var tb=0;tb<4;tb )
{
m2 = m[tb];
for (var tc=0;tc<4;tc )
{
m3 = m[tc];
for (var k=1;k<11;k )
{
eval("test(exp" k ",a,b,c,d,m1,m2,m3);");
}
}
}
}
}
}
}
}
}
</script>
</body>

</html> 织梦好,好织梦

看完这篇,您有何感觉呢?

文章评论

共有位Admini5网友发表了评论 查看完整内容

24小时热门信息