For example, two-digit number have 4 combinations: 11, 12, 21, 22. Three-digit number have 8 combinations: 111, 112,…222.
- How to get number of combinations for number that have 4, 5, … 10 or more digits?
Thanks
P.S. This refers to the Delphi 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The answer is 2N, where N is the number of digits.
This is a purely mathematical problem, and concerns very basic combinatorics. It is easy to see why 2N is the right answer. Indeed, there are two ways to choose the first digit. For each such choice, there are two ways to chose the second digit. Hence, there are 2×2 ways to chose a two-digit number. For each such number, there are two ways to add a third digit, making 2×2×2 ways to construct a three-digit number. Hence, there are
ways to construct a N-digit number.
In Delphi, you compute 2N by
Power(2, N)(uses Math). [A less naïve way, which works for N < 31, is1 shl N.]