1

I bought three boxes of tea bags with different flavors (A, B, C).

I wish to mix them in such a way that - there is never two consecutive bags of the same flavor (ABCCAB is avoided) ; - the mixing is the "most" random, i.e. avoid patterns such as ABCABCABC... or ABABAB...BCBCBC...CACACA.

Is there a known algorithm for this mix ?

Presently I randomly shuffle many "ABC" and concatenate the results, swapping the first letters if the latest letter of the previous shuffle is the same than the beginning of the new shuffle (...ABCCAB => ...ABCACB).

I guess I could improve this algorithm by pre-computing the permutations of ABC, and draw one permutations among the ones who do not begin with the same letter than the previous permutation.

I tried to "google" this problem but as a French native speaker, I probably miss the appropriate key-words.

  • 4
  • @gnat : I agree. Need to be deeply studied. – Dominique Nov 30 '18 at 16:07
  • 4
    "most random" hmm – Ewan Nov 30 '18 at 16:50
  • 1
    I think what Ewan is trying to say there is, it sounds like you have a requirement in mind that is not adequately conveyed by the single word, "random." Maybe you want to say something like, "no span of n tea bags shall contain fewer than m instances of any one flavor." (for some suitable choice of n and m, of course.) – Solomon Slow Nov 30 '18 at 19:21
  • @SolomonSlow I think we can get by with a simple goal like: all valid sequences are equally likely. – candied_orange Nov 30 '18 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.