RRRRB

RRRBR

RRRBB

RRBRR

RRBRB

RRBBR

RRBBB

RBRRR

RBRRB

RBRBR

RBRBB

RBBRR

RBBRB

RBBBR

RBBBB

BRRRR

BRRRB

BRRBR

BRRBB

BRBRR

BRBRB

BRBBR

BRBBB

BBRRR

BBRRB

BBRBR

BBRBB

BBBRR

BBBRB

BBBBR

BBBBB

Solved

Posted on 2011-10-28

need all possible variations of RED or BLACK for 5 roulette spins.

15 Comments

RRRRB

RRRBR

RRRBB

RRBRR

RRBRB

RRBBR

RRBBB

RBRRR

RBRRB

RBRBR

RBRBB

RBBRR

RBBRB

RBBBR

RBBBB

BRRRR

BRRRB

BRRBR

BRRBB

BRBRR

BRBRB

BRBBR

BRBBB

BBRRR

BBRRB

BBRBR

BBRBB

BBBRR

BBBRB

BBBBR

BBBBB

So the sequence is really:

[RED | BLACK | GREEN] ^ (number-spins)

e.g. for 2 spins:

RR

RB

RG

BR

BB

BG

GR

GB

GG

The pattern should be pretty obvious :)

Doug

[00000] can have the same logical meaning as [RRRRR]. Likewise, [01100] can be used to represent [RBBRR].

From there, it should be clear that "all possible variations of RED or BLACK for 5 roulette spins" is just a different way of saying "all binary numbers from 00000 to 11111".

Tom

You are posting this in the AS/400 zone, do you need AS/400 routines (RPG) for this?

Sorry,i do not understand what you mean.

So I was wondering if you need this for an AS/400 system?

If not what language can you read, I can send you a routine, even a EXCEL macro if you like?

A simple for-loop can do this. In c, it's

for (i = 0; i< (2 <<num_digits); i++){desired-action-goes-h

where num_digits is 5 to 10 or maybe even 15.

mtgradwell is right, but that works only for the situation Red vs. Black. if green is involved, I'm not sure if it will function.

but theoretically it's not that complex,

In a binary system you have 2 digits (0 to 1), so 2 is the base number

in a decimal system you have 10 digits (0 to 9) so 10 is the base the number

in a Binary 101 means

1 * 2^0 = 1 * 1 = 1

0 * 2^1 = 0 * 2 = 0

1 * 2^2 = 1 * 4 = 4

total = 5 so 101 is 5

in a Decimal system

1 * 10^0 = 1 * 1 = 1

0 * 10^1 = 0 * 10 = 0

1 * 10^2 = 1 * 100 = 100

total = 101 so 101 is 101 :)

If we use that in an Octal system 8 digits (0-7)

1 * 8^0 = 1 * 1 = 1

0 * 8^1 = 0 * 8 = 0

1 * 8^2 = 1 * 64 = 64

total = 65 so 101 is 65

and yes hexadecimal works the same :-)

Knowing this you can program whatever language you like, the basics are all the same.

Regards,

murph

```
public class MyPow {
public static void main(String argv[]) {
int limit = 5;
String a = "";
String b = "";
for (int j = 0; j < limit ; j++)
a = a + "R";
for(int i=0;i<Math.pow(2, limit);i++) {
b = a + Integer.toBinaryString(i);
System.out.println((b.substring(b.length()-limit).replace('0','R')).replace('1','B'));
}
}
}
```

It uses It creates a simple string of Rs first -- that string is as wide as the number of spins, so it creates "RRRRR" when

It then loops through binary numbers from zero through 2 raised to the power of

The right-most substring is taken from that string for

Change

Tom

Title | # Comments | Views | Activity |
---|---|---|---|

Best approach for convert Excel sheets with "junk data" to SQL 2008? | 5 | 404 | |

Calculating length of base64 encoded string: proof/explanation needed | 4 | 2,115 | |

is there a better algorithms for this case? | 12 | 132 | |

Math home work questions | 5 | 44 |

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**18** Experts available now in Live!