# Thread: recursion? combinations of numbers

1. ## recursion? combinations of numbers

I've been working on this program for almost 3 weeks, but I can not figure out how to do it. Let me know if you can help.

i have to write a program using recursion to print a list of number possibilities from a given set of numbers of a given number of digits.

Sample input:
3 2
3 5 6
0

3 is the amount of numbers in the set.
2 is the amount of digits in the output numbers.
3 5 6 is the set of numbers
0 tells the program to quit

sample out put would look like:
33 35 36 53 55 56 63 65 66

so everything comes down to 1 function that i cant write recursively for the life of me.
iteratively, it is simple but that's not acceptable as a solution.

my program takes in the number set, sorts them by ascending, stores them in an array, and then ... blank.

i just cant get my mind to process this recursively. this program is an assignment so i can not post code.

let me know if you can help. thanks.

2. Originally Posted by ominub
this program is an assignment so i can not post code.
Pretty sure the answer then is DITTO. If you are having trouble with your code and want to post what you have tried, someone may critique it or make suggestions.

Everyone else is comfortable posting code when they are working on an assignment, just look around.

Otherwise, you are just asking someone to do your homework for you, which is against cboard policy.

3. Code:
`iteratively, it is simple but that's not acceptable as a solution.`
How do you do it iteratively? If you have some sort of data structure that you're storing information in in a stack-like manner, you may be able to turn the stack into the function call-stack.

A hint for a recursive solution: you're basically calculating permutations with repetitions. Recursion is all about breaking problems down into smaller ones. Let's say your numbers are 0 and 1, and you want permutations of length 2. What possibilities are there? There's 0N and 1N, where 'N' is all of the permutations of length 2-1. What are the permutations of length 1? 0N and 1N, where 'N' is all of the permutations of length 1-1. What are the permutations of length 0? Just the empty string.