search

Home  >  Q&A  >  body text

javascript - How to use programming algorithm to solve mathematical permutations and combinations?

It seems that recursion is used, can you explain the idea?

phpcn_u1582phpcn_u15822750 days ago497

reply all(3)I'll reply

  • 阿神

    阿神2017-05-19 10:10:12

    var A = function(N,M,num){
        if( N < M || N <= 0) return 0;
        num = num || 1;
        if( M == 0 ) return num;
        return A(N-1,M-1,N * num);
    };
    //A排列
    
    var C = function(N,M){
        return A(N,M) / A(M,M);
    };
    //C组合 ,应该就这样了

    reply
    0
  • ringa_lee

    ringa_lee2017-05-19 10:10:12

    Refer to this article http://www.cnblogs.com/kaiye/...

    reply
    0
  • 黄舟

    黄舟2017-05-19 10:10:12

    github source code https://github.com/treeandgra...

    reply
    0
  • Cancelreply