Results js known number plus the number of unknowns, each of the three figures will not be repeated

Conditions: two three-digit sum, the result is four digits, each digit and all numbers are not repeated, a + 284 = c, and find a C?

var a,b=284,c;
for(var a=102;a<=987;a++){
c=a+b;
var a_arr=a.toString().split("");
var b_arr=b.toString().split("");
var c_arr=c.toString().split("");
var res_arr=a_arr.concat(b_arr).concat(c_arr);
if(new Set(res_arr).size==10){console.log(a+"+"+b+"="+c)}
}

769+284=1053

 As an extension of the above conditions: two three unknowns are added, the result is four digits, each digit and the number of all can not be repeated, a + b = c, find a, b, c?

var a,b,c,i=1;
for(var a=102;a<=987;a++){
	for(var b=102;b<=987;b++){
	c=a+b;
	var a_arr=a.toString().split("");
	var b_arr=b.toString().split("");
	var c_arr=c.toString().split("");
	var res_arr=a_arr.concat(b_arr).concat(c_arr);
	if(new Set(res_arr).size==10){console.log(a+"+"+b+"="+c);i++}
    }
}
console.log("总共有多少组:"+i+"组");

 

Published 46 original articles · won praise 9 · views 3643

Guess you like

Origin blog.csdn.net/weixin_41896770/article/details/103106055