lundi 28 novembre 2016

Conditional Randomization

Imagine there is a list of elements as follow:

1a, 2a, 3a, 4a, 5b, 6b, 7b, 8b

Now we need to randomize it such that not more than 2 "a"s or 2 "b"s get next to each other. For instance the following list is not allowed because of the 2nd, third and fourth elements:

3a, 7b, 8b, 5b, 2a, 1a, 5b, 4a

How can we write write an efficient code without generating many random sequences and many triad comparisons?

Thanks,




Aucun commentaire:

Enregistrer un commentaire