24值计算

function Button1_onclick() {
var str=document.getElementById('TextBox1').value+document.getElementById('TextBox2').value+document.getElementById('TextBox3').value+document.getElementById('TextBox4').value;
var operator='+-*/';
for(var a=0;a<4;a++)
{
    for(var m=0;m<4;m++)
    {
        for(var b=0;b<4;b++)
        {
            if(b!=a)
            {
                for(var n=0;n<4;n++)
                {
                    for(var c=0;c<4;c++)
                    {
                        if(c!=a && c!=b)
                        {
                            for(var k=0;k<4;k++)
                            {
                                for(var d=0;d<4;d++)
                                {
                                    if(d!=a && d!=b && d!=c)
                                    {
                                        if(eval(str.substr(a,1)+operator.substr(m,1)+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+operator.substr(k,1)+str.substr(d,1))==24)
                                        {
                                            document.writeln(str.substr(a,1)+operator.substr(m,1)+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+operator.substr(k,1)+str.substr(d,1)+'<br>');
                                        }
                                        if(eval('('+str.substr(a,1)+operator.substr(m,1)+str.substr(b,1)+')'+operator.substr(n,1)+str.substr(c,1)+operator.substr(k,1)+str.substr(d,1))==24)
                                        {
                                            document.writeln('('+str.substr(a,1)+operator.substr(m,1)+str.substr(b,1)+')'+operator.substr(n,1)+str.substr(c,1)+operator.substr(k,1)+str.substr(d,1)+'<br>');
                                        }
                                      
                                        if(eval(str.substr(a,1)+operator.substr(m,1)+str.substr(b,1)+operator.substr(n,1)+'('+str.substr(c,1)+operator.substr(k,1)+str.substr(d,1)+')')==24)
                                        {
                                            document.writeln(str.substr(a,1)+operator.substr(m,1)+str.substr(b,1)+operator.substr(n,1)+'('+str.substr(c,1)+operator.substr(k,1)+str.substr(d,1)+')'+'<br>');
                                        }
                                        if(eval(str.substr(a,1)+operator.substr(m,1)+'('+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+')'+operator.substr(k,1)+str.substr(d,1))==24)
                                        {
                                            document.writeln(str.substr(a,1)+operator.substr(m,1)+'('+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+')'+operator.substr(k,1)+str.substr(d,1)+'<br>');
                                        }
                                        if(eval('('+str.substr(a,1)+operator.substr(m,1)+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+')'+operator.substr(k,1)+str.substr(d,1))==24)
                                        {
                                            document.writeln('('+str.substr(a,1)+operator.substr(m,1)+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+')'+operator.substr(k,1)+str.substr(d,1)+'<br>');
                                        }
                                        if(eval(str.substr(a,1)+operator.substr(m,1)+'('+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+operator.substr(k,1)+str.substr(d,1)+')')==24)
                                        {
                                            document.writeln(str.substr(a,1)+operator.substr(m,1)+'('+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+operator.substr(k,1)+str.substr(d,1)+')'+'<br>');
                                        }
                                        if(eval('(('+str.substr(a,1)+operator.substr(m,1)+str.substr(b,1)+')'+operator.substr(n,1)+str.substr(c,1)+')'+operator.substr(k,1)+str.substr(d,1))==24)
                                        {
                                            document.writeln('(('+str.substr(a,1)+operator.substr(m,1)+str.substr(b,1)+')'+operator.substr(n,1)+str.substr(c,1)+')'+operator.substr(k,1)+str.substr(d,1)+'<br>');
                                        }
                                       
                                        if(eval('('+str.substr(a,1)+operator.substr(m,1)+'('+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+'))'+operator.substr(k,1)+str.substr(d,1))==24)
                                        {
                                            document.writeln('('+str.substr(a,1)+operator.substr(m,1)+'('+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+'))'+operator.substr(k,1)+str.substr(d,1)+'<br>');
                                        }
                                        if(eval(str.substr(a,1)+operator.substr(m,1)+'(('+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+')'+operator.substr(k,1)+str.substr(d,1)+')')==24)
                                        {
                                            document.writeln(str.substr(a,1)+operator.substr(m,1)+'(('+str.substr(b,1)+operator.substr(n,1)+str.substr(c,1)+')'+operator.substr(k,1)+str.substr(d,1)+')'+'<br>');
                                        }
                                         if(eval(str.substr(a,1)+operator.substr(m,1)+'('+str.substr(b,1)+operator.substr(n,1)+'('+str.substr(c,1)+operator.substr(k,1)+str.substr(d,1)+'))')==24)
                                        {
                                            document.writeln(str.substr(a,1)+operator.substr(m,1)+'('+str.substr(b,1)+operator.substr(n,1)+'('+str.substr(c,1)+operator.substr(k,1)+str.substr(d,1)+'))'+'<br>');
                                        }/* */
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
}

posted on 2007-12-05 18:47  ferrari  阅读(204)  评论(0编辑  收藏  举报

导航