I am writing an application in PHP where users can enter two sets of information and have every possible combination of the two sets printed out. The goal is to use it as a teaching tool for learning language by practicing different patterns of a question and answer.
For example, we may practice the question "Have you ever tried...?" plus one of four activities, such as bungee jumping, para sailing, skydiving, and scuba diving. There would also be four possible answers:
- Yes I have, and I enjoyed it.
- Yes I have, but I didn't like it.
- No I haven't, but I want to try it.
- No I haven't, and I don't want to try it.
The user would input the two sets of data, and the application would then print sheets of cards containing all possible combinations of the questions and answers. For example, card 1 would look like this:
- skydiving: Yes I have, and I enjoyed it.
- scuba diving: Yes I have, but I didn't like it.
- parasailing: No I haven't, but I want to try it.
- bungee jumping: No I haven't, and I don't want to try it.
The next card might then look like this:
- skydiving: Yes I have, but I didn't like it.
- scuba diving: No I haven't, but I want to try it.
- parasailing: No I haven't, and I don't want to try it.
- bungee jumping: Yes I have, and I liked it.
So as you can see, there are many different possible combinations. The idea would be that both lists would be of the same length to allow all of the possibilities to be printed out. It is also important that no question or answer gets used more than once on any card, and that two cards can be alike. What would be the best way to go about this? The actual input and output is not the problem--I've done similar things before. I just need the algorithm to produce the combinations.
EDIT: I guess what I'm really after is to keep the activities in the same order for each card, but have every possible combinations of answers. So what I really need is to be able to produce the following set of indexes for getting data out of the answers array. So I really want something more like this:
- 0,1,2,3
- 0,1,3,2
- 0,2,1,3
- 0,2,3,1
- 0,3,1,2
- 0,3,2,1
- 1,0,2,3
- 1,0,3,2
- 1,2,0,3
- 1,2,3,0
...and so on until all possible combinations have been produced.