【js】1-9任意插入加减号,值为100 ,如:1+23-4+56+7+8+9=100

 

 

//1-9任意插入加减号,值为100
//如:1+23-4+56+7+8+9=100

while(true){
    let sum = "1" + ["","+","-"][Math.round(Math.random()*2)];
    sum += "2" + ["","+","-"][Math.round(Math.random()*2)];
    sum += "3" + ["","+","-"][Math.round(Math.random()*2)];
    sum += "4" + ["","+","-"][Math.round(Math.random()*2)];
    sum += "5" + ["","+","-"][Math.round(Math.random()*2)];
    sum += "6" + ["","+","-"][Math.round(Math.random()*2)];
    sum += "7" + ["","+","-"][Math.round(Math.random()*2)];
    sum += "8" + ["","+","-"][Math.round(Math.random()*2)] + "9";
    if(eval(sum) == 100){
        console.log(sum + " = 100");
        break;
    }
}

  目前代码只能随机生成一个,之后还会更新。

上一篇:LeetCode 面试题56 数组中数字的出现次数


下一篇:88、go框架有哪些-转载——2020年07月30日12:56:43