I’m stuck on how to begin coding this.
I want to be able to do the following. It’s a classic flipping the coin problem
If I flip twice the out comes are:
T T
T F
F T
F F
I want to be able to create an array with one result at a time. To better illustrate this, it should be something like (I’m using Java by the way):
boolean[] cases = new boolean[numberOfFlips]
the first time cases will have: T T.
After I’m done doing other calculations with this result I want to move on and now make cases: T F and proceed with running other calculations.
Can someone guide me in the right direction please? I would greatly appreciate it.
An algorithm in any language is fine with me. Thank you for your time! (:
There are many ways to store binary data in Java and it is unclear, what you want to store. If you want to store ALL possible combinations of
Nflippings, then you need and arraynew boolean[2^N][N]Remember that Java has another syntax for raising to power.
UPDATE
Below is the code for storing all combinations of
Nflips.From it you will get an idea how to generate one combination too: from binary representation of combination ordinal number. See comments.