def color(paint): This problem was inspired by the fun little Mathologer video “Secret of Row 10” whose fractal animation once again remind us about how moving from two to three often opens the barn door for the chaos horse to emerge and wildly gallop away. To start, look at three values imaginatively named “orange”, “purple” and “green”. These names serve as colorful (heh) mnemonics that could just as well have been “foo”, “bar” and “baz”, so no connection to actual physical colors is intended or implied. Next, define a simple mixing rule between these colors with a rule that says that whenever any color is mixed with itself, the result is that same color, whereas mixing two different colors always gives the third. For example, mixing green to green gives that same green, whereas mixing green to purple gives orange.. Given the first row of colors as a string of lowercase letters to denote these colors, this function should construct the rows below the first row one at the time according to the following discipline. Each row always contains one fewer element than the previous row above it. The i:th element of each row is calculated by mixing the colors of the previous row in positions i and i + 1. The singleton element of the bottom row is returned as the final answer. For example, starting from the first row 'gopog' leads to 'pggp', which leads to 'ogo', which leads to 'pp', which leads to 'p' as the final answer, Regis. When the Python virtual machine goes 'pggggg', that in turn leads to 'ogggg', 'pggg' , 'ogg', 'pg' for the final answer 'o' for “Yes, please!” paint Expected result 'g' 'g' 'pp' 'p' 'ogpgog' 'o' 'pogppo' 'o' 'opgogoopgopp' 'g' 'goppppoggogpp' 'p'
Question
def color(paint):
This problem was inspired by the fun little Mathologer video “Secret of Row 10” whose fractal animation once again remind us about how moving from two to three often opens the barn door for the chaos horse to emerge and wildly gallop away. To start, look at three values imaginatively named “orange”, “purple” and “green”. These names serve as colorful (heh) mnemonics that could just as well have been “foo”, “bar” and “baz”, so no connection to actual physical colors is intended or implied. Next, define a simple mixing rule between these colors with a rule that says that whenever any color is mixed with itself, the result is that same color, whereas mixing two different colors always gives the third. For example, mixing green to green gives that same green, whereas mixing green to purple gives orange..
Given the first row of colors as a string of lowercase letters to denote these colors, this function should construct the rows below the first row one at the time according to the following discipline. Each row always contains one fewer element than the previous row above it. The i:th element of each row is calculated by mixing the colors of the previous row in positions i and i + 1. The singleton element of the bottom row is returned as the final answer. For example, starting from the first row 'gopog' leads to 'pggp', which leads to 'ogo', which leads to 'pp', which leads to 'p' as the final answer, Regis. When the Python virtual machine goes 'pggggg', that in turn leads to 'ogggg', 'pggg' , 'ogg', 'pg' for the final answer 'o' for “Yes, please!”
paint |
Expected result |
'g' |
'g' |
'pp' |
'p' |
'ogpgog' |
'o' |
'pogppo' |
'o' |
'opgogoopgopp' |
'g' |
'goppppoggogpp' |
'p' |
Step by step
Solved in 2 steps