//1-9任意插入加减号,值为100
//如:1+23-4+56+7+8+9=100
let s = new Set(); //设置相互独立的非重复值
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){
s.add(sum); //add() 方法用来向一个 Set 对象的末尾添加一个指定的值
}
let index = "0";
if(s.size == 11){ //这里我运算过有11个,做个判断跳出循环
s.forEach(function(v,i){
console.log(`${++index}.${v} = 100`); //单引号,模板字符串
})
break;
}
}