Skip to main content
added 135 characters in body; added 5 characters in body
Source Link
Tony Huynh
  • 32.1k
  • 11
  • 112
  • 187

Without loss of generality, assume $n \leq m$. Such a colour code ordering is just a sequence of alternating $R$ and $B$ letters. There are four types of such sequences, depending which letter they start and end with. Say a sequence is of type $(X,Y)$ if it begins with $X$ and ends with $Y$.

So, there are

  1. $n$ sequences of type $(R,B)$
  2. $n$ sequences of type $(B,R)$
  3. $n-1$ sequences of type $(R,R)$
  4. $n$ sequences of type $(B,B)$ (and only $n-1$ of them if $n=m$).

Thus, the answer is $4n-1$ if $n < m$, and $4n-2$ if $n=m$.

Edit. As Larry Denenberg mentions, in the degenerate case of $n=0$, the answer is always 1 (I count the empty string if $n=m=0$).

Without loss of generality, assume $n \leq m$. Such a colour code ordering is just a sequence of alternating $R$ and $B$ letters. There are four types of such sequences, depending which letter they start and end with. Say a sequence is of type $(X,Y)$ if it begins with $X$ and ends with $Y$.

So, there are

  1. $n$ sequences of type $(R,B)$
  2. $n$ sequences of type $(B,R)$
  3. $n-1$ sequences of type $(R,R)$
  4. $n$ sequences of type $(B,B)$ (and only $n-1$ of them if $n=m$).

Thus, the answer is $4n-1$ if $n < m$, and $4n-2$ if $n=m$.

Without loss of generality, assume $n \leq m$. Such a colour code ordering is just a sequence of alternating $R$ and $B$ letters. There are four types of such sequences, depending which letter they start and end with. Say a sequence is of type $(X,Y)$ if it begins with $X$ and ends with $Y$.

So, there are

  1. $n$ sequences of type $(R,B)$
  2. $n$ sequences of type $(B,R)$
  3. $n-1$ sequences of type $(R,R)$
  4. $n$ sequences of type $(B,B)$ (and only $n-1$ of them if $n=m$).

Thus, the answer is $4n-1$ if $n < m$, and $4n-2$ if $n=m$.

Edit. As Larry Denenberg mentions, in the degenerate case of $n=0$, the answer is always 1 (I count the empty string if $n=m=0$).

added 16 characters in body; deleted 16 characters in body
Source Link
Tony Huynh
  • 32.1k
  • 11
  • 112
  • 187
Source Link
Tony Huynh
  • 32.1k
  • 11
  • 112
  • 187

Without loss of generality, assume $n \leq m$. Such a colour code ordering is just a sequence of alternating $R$ and $B$ letters. There are four types of such sequences, depending which letter they start and end with. Say a sequence is of type $(X,Y)$ if it begins with $X$ and ends with $Y$.

So, there are

  1. $n$ sequences of type $(R,B)$
  2. $n$ sequences of type $(B,R)$
  3. $n-1$ sequences of type $(R,R)$
  4. $n$ sequences of type $(B,B)$ (and only $n-1$ of them if $n=m$).

Thus, the answer is $4n-1$ if $n < m$, and $4n-2$ if $n=m$.