← RoseCode

ROSECODE 250

Colored coins

Philippe_57721 · Programming ·

T(n) is the n-th triangular number.

T(n) coins are arranged in a triangle.
We color each coin with 4 different colors such as no two touching coins have the same color.

For n=2, there are 24 possible configurations:
+---+ +---+ +---+ +---+ +---+ +---+
| 1 | | 1 | | 1 | | 1 | | 1 | | 1 |
|2 3| |2 4| |3 2| |3 4| |4 2| |4 3|
+---+ +---+ +---+ +---+ +---+ +---+

+---+ +---+ +---+ +---+ +---+ +---+
| 2 | | 2 | | 2 | | 2 | | 2 | | 2 |
|1 3| |1 4| |3 1| |3 4| |4 1| |4 3|
+---+ +---+ +---+ +---+ +---+ +---+

+---+ +---+ +---+ +---+ +---+ +---+
| 3 | | 3 | | 3 | | 3 | | 3 | | 3 |
|1 2| |1 4| |2 1| |2 4| |4 1| |4 2|
+---+ +---+ +---+ +---+ +---+ +---+

+---+ +---+ +---+ +---+ +---+ +---+
| 4 | | 4 | | 4 | | 4 | | 4 | | 4 |
|1 2| |1 3| |2 1| |2 3| |3 1| |3 2|
+---+ +---+ +---+ +---+ +---+ +---+

We represent a configuration:
+-----+
| A |
| B C |
|D E F|
+-----+
as A,BC,DEF

How many configurations are there for n = 10?
What is the 10,000,000 th (in lexicographic order)?

Example: 192/1,32,214 If we ask the 20-th configuration for n=3

[My timing: 7 sec]