Question: Answer all 2a. Write a function to test whether a coloring of the last map in Basic Counting Practice Exercise 5 has two adjacent colors.

Answer all

2a. Write a function to test whether a coloring of the last map in Basic Counting Practice Exercise 5 has two adjacent colors. Diagonal squares of the same color do not count as adjacent. You can store your map as a list of two length-three lists or, if you are familiar with SymPy, as a 2 by 3 Matrix. The same code will work for either, but you can pick one and stick with it if you prefer.

>>> valid_coloring([[1,2,3],[2,1,2]]) True >>> valid_coloring([[1,2,3],[2,1,3]]) False

2b. Write a function which takes in a total number of colors and returns the total number of map colorings with no two adjacent countries of the same color.

>>> valid_map_count(2) 2 >>> valid_map_count(3) 54

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!