var existSameN = function (arr){ for(var i = 0; i < arr.length; i++){ for(var j = 0; j < arr.length ; j++){ if(j == i){continue;} if(arr[i] == arr[j]) {return true;} } } return false; } var ret = new Array(); for(var i = 1000; i< 9999; i++){ var strI = i.toString(); var arr = new Array(strI[0],strI[1],strI[2],strI[3]); if(existSameN(arr)){continue;} var reverseI = parseInt(strI[3] + strI[2]+strI[1]+strI[0]); for(var j = 1; j<= 9 ; j++){if(i * j == reverseI) {ret.push( {num:i,mul:j});}} } for(var i = 0;i < ret.length; i++) console.log("number : " + ret[i].num + ", multiply by : " + ret[i].mul);
算法练习--ABCD*E=DCBA,布布扣,bubuko.com
原文:http://blog.csdn.net/lan_liang/article/details/36865979