I need to write a Perl routine that will generate the n choose k combinations of a given set. I don’t need to count how many sets there are, I have to be able to print them out. I’m pretty stumped.
Any advice is appreciated.
Regards.
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.
If you want combinations without repetition, you can generate all binary numbers to length k, select those that have n 1’s and apply them to the set in a fixed order: 0 means not selected, 1 means selected. To get a binary number, use
sprintf '%05b'; to count 1’s usetr/1//.