zoukankan      html  css  js  c++  java
  • 算法练习--ABCD*E=DCBA



    //1.ABCD * E = DBCA
    //2.A,B,C,D {0-9} , E {1-9}
    //3.A,B,C,D,E all different 


    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);


  • 相关阅读:
    canvas之碎碎念
    canvas之动态时钟
    属性小问题
    readonly and disabled
    table
    地图热区
    子块元素在父块元素中居中
    Ajax与JS
    前端测试
    html5/css3
  • 原文地址:https://www.cnblogs.com/yxysuanfa/p/7250950.html
Copyright © 2011-2022 走看看