I’m taking an exam tomorrow, and on that exam there is a bit about probability. Now on many of those tasks one is to find all the outcomes. That can sometimes be tricky to get right. Let’s say you have two players playing rock-paper-scissors. One player is John, the other is Reese. The two play three games in a row. All the possible outcomes of this set with three rounds can be represented as JTR. That would be John wins first round, then there is a tie and then Reese wins a round. I know that there is 3*3*3=27 different outcomes. I am allowed to use my computer on the exam, and a short snippet of code that would given any letters, in this case at least write out all the 27 combinations would be really nice! I only ask in case there is some known algorithm that does this, I’ll be hacking away at it myself as of this moment. Any suggestions will be really much appreciated!
Share
Try the following function:
Call it like this:
The first argument is an array of the items you want to permute, the second argument is an empty array that’s as long as you want the permutations to be, and the third argument should be 0 to kick it off.