Algorithm for finding a permutation combination

Source: Internet
Author: User
That is true
Randomly extract 3 numbers from the 36 characters of 0~9,a~z to calculate how many permutation combinations are available
Ask the Great God for advice


Reply to discussion (solution)

36*36*36=46656

36*36*36

Forget it, I wrote it.

/** * Permutation combination algorithm * C ($n, $m) * Number of $n elements * $m number of elements taken from $n * $num total number of combinations **/function get_combination ($n, $m) {if (Is_int ($n) &am p;& Is_int ($m)) && ($m <= $n)) {$a = 1;//initialize for ($i =1; $i <= $m; $i + +) {$a = $n * $a; $b = 1* $i; $n--;} $num = $a/$b; return $num;}}

Combination formula: C (n,m) =p (n,m)/m!=n!/((n-m)!*m!)
Do you think you are right?

Combination formula: C (n,m) =p (n,m)/m!=n!/((n-m)!*m!)
Do you think you are right?


You can try.

36*35*34

Calculated by the combined formula is 7140
Half less than you.


Combination formula: C (n,m) =p (n,m)/m!=n!/((n-m)!*m!)
Do you think you are right?


You can try.

echo get_combination (3,3);
Output 2
It's not right, is it?

echo get_combination (3,3);
Output 2
It's not right, is it?


Yes, just looked.
The formula you wrote is also wrong.
If you press your formula,
Two numbers from 2 numbers equals 1.

Right
The combination of two numbers from 2 numbers is 1.
The arrangement is 2.
P (n,m) =n (n-1) (n-2) ... (n-m+1) =n!/(N-M)! (stipulated 0!=1).

Add the following 3 numbers can be the same

For example, extracting a random two number from an array can be
11
22
12
21st

Right
The combination of two numbers from 2 numbers is 1.
The arrangement is 2.
P (n,m) =n (n-1) (n-2) ... (n-m+1) =n!/(N-M)! (stipulated 0!=1).



All right, I'm going to go around.
N^m is OK.
Thank you.
It's been a tangle of permutations and combinations.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.