Colour trio
Tags: Algorithms Math Combinatorics Simulation
Credit: Ilkka Kokkarinen
Difficulty: Medium
Type: Text
Category: Practice
Time Allowed: 15 s
Description:
This problem was inspired by the Mathologer video “Secret of Row 10”
. To start, assume the existence of three values called “red”, “yellow” and “blue”. These names serve as colourful (heh) mnemonics and could as well have been 0, 1, and 2, or “foo”, “bar” and “baz”; no connection to actual physical colours is implied. Next, define a rule to mix such colours so that mixing any colour with itself gives that same colour, whereas mixing any two different colours always gives the third colour. For example, mixing blue to blue gives that same blue, whereas mixing blue to yellow gives red, same as mixing yellow to blue, or red to red.
Given the first row of colours
as a string of lowercase letters, this function should construct the rows below the first row one row at the time according to the following discipline. Each row is one element shorter than the previous row. The i:th element of each row comes from mixing the colours in positions i and i+1 of the previous row. Rinse and repeat until only the singleton element of the bottom row remains, returned as the final answer. For example, starting from 'rybyr' leads to 'brrb', which leads to 'yry', which leads to 'bb', which leads to 'b' for the final answer, Regis. When the Python virtual machine laughs and goes 'brrrrr', that will lead to 'yrrrr', 'brrr', 'yrr', and 'br' for the final answer 'y' for “Yes, please!”
(Today's five-dollar power word to astonish your friends and coworkers is “quasigroup”
.)
Test Case | Input | Expected Output |
---|---|---|
1 | 'y' | 'y' |
2 | 'bb' | 'b' |
3 | 'rybyry' | 'r' |
4 | 'brybbr' | 'r' |
5 | 'rbyryrrbyrbb' | 'y' |
6 | 'yrbbbbryyrybb' | 'b' |
Leave a Comment
Please login to leave a comment.