Your program should generate each combination once, but not more than once. The order in which the combinations are produced is up to you. Ignore the possibility of numbers being pushed together at the same time. Your solution must be generalized to N buttons - i.e., the number of buttons is a parameter that the program accepts.
You may assume that the number of buttons never exceeds 8.
Valid combinations include
| 4 | (just one button) |
| 1 2 | (does not use all buttons) |
| 1 5 2 4 3 | (uses all buttons) |
Invalid combinations include:
| 1 2 1 | (uses a button more than once) |
| _ | (does not use ANY buttons) |
I am looking for a short and simple solution. Please include comments in your program.
Additional part:
Include all combinations that contain pairs of buttons pushed together. Denote numbers pushed together with dashes, i.e., 1 and 3 together as 1-3
Valid pairings include:
| 1-2 | (One pair) |
| 2-3 1-4 5 | (multiple pairs) |
| 1-2 3-4 | (any number of buttons together) |
Invalid pairings include:
| 1-2 2-3 | (uses a button more than once) |
| 1-2-3 4 | (must not push more than two buttons at once) |
| 1-2 & 2-1 | (order of the pairs does not matter) |
Your solution should be in the form of a C program that takes one command line argument. Your solution should be well under 100 lines of C code, not counting blank or comment lines. For the case of a trivial button lock with only two buttons, running your program should look something like the following: