British Algorithmic Olympiad 2024
Question 4. Colour Codes A The input is an array of 7 non-negative integers c ; sum(c) is the number $n$ of letters in the colour code. It is the case that some of the letters could be repeating as in the example given. To generate permutations straight insertion is a method that easy to code (and understand). If the string is $\tt{RRYB}$ we can pick the first character in the sequence. The one element array $\begin{array}{|c|}\hline \tt{R} \\ \hline \end{array}$ has two insertion points: before and after. However in this case both insertion points generate exactly the same permutation namely $\begin{array}{|c|c|}\hline \tt{R} & \tt{R} \\ \hline \end{array}$. As a general rule, if at an insertion point $i$, the character we are inserting is the same as the array element at that insertion point, we can skip the insertion. We can summarise the procedure using the following Python...