Java, Recursion and Combinations
843789Aug 11 2009 — edited Aug 12 2009I have been doing a few mathematical java recursion problems lately to get in the swing of things with the logic, and have come across a program I simply cannot seem to solve.
There are four balls in a bag, black, red, blue and yellow. At random, a ball is pulled from the bag, and then placed back into the bag. Write a program that uses a recursive method to print out all combinations for a given number of draws (no loops allowed)
The extra part says the number of combinations can be printed after output.
The hints in the book state that the recursion method is really short and efficient and can be done in <10 lines, with no arrays, or loops, don?t fight the recursion! I cannot wrap my mind around how to go about this, here is the examples:
***********
Eg 1.
***********
1
Black
Red
Blue
Yellow
4 Combinations
***********
Eg 2.
***********
2
Black Black
Black Red
Black Blue
Black Yellow
Red Black
Red Red
Red Blue
Red Yellow
Blue Black
Blue Red
Blue Blue
Blue Yellow
Yellow Black
Yellow Red
Yellow Blue
Yellow Yellow
16 Combinations
Any help or pointers would be apppreciated.