Problem :
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.

Implementation :


var sameDig = function f(n1,n2){

var strN1 = n1.toString();
var strN2 = n2.toString();


if(strN1.length != strN2.length) return false;


var arr1 = new Array();
var arr2 = new Array();


for(var i = 0;i < strN1.length; i++){
arr1.push(strN1[i]);
arr2.push(strN2[i]);
}


arr1.sort();
arr2.sort();


for(var i = 0;i < arr1.length; i++){ if(arr1[i]!=arr2[i]) return false;}


return true;


}


for(var i = 1;i < 999999; i++){
if(sameDig(i,2*i) &&
sameDig(i,3*i) &&
sameDig(i,4*i) &&
sameDig(i,5*i) &&
sameDig(i,6*i)) {console.log(i); break;}
}


转载于:https://www.cnblogs.com/jzssuanfa/p/6900742.html

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐