# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1662: Red face?

From New Scientist #2828, 3rd September 2011 [link]

Our local craft shop stocks an ornament made of a piece of carved wood. Its surface consists of a number of faces, all being different colours but the same-sized regular polygon, and with the same number of faces meeting at each vertex. I bought a number of these ornaments, all absolutely identical, and placed them on my mantelpiece.

My nephew saw them and noted that three of them had the same colour face resting on the mantelpiece and that in all other cases the colours were different. “That’s an unnatural set-up,” he commented, and he arranged them so that all the colours resting on the surface were different.

However, he was embarrassed when I proved to him that the previous situation was more natural because, if the ornaments were placed at random, then there was 50 per cent more chance of having three the same (and the rest different) than having them all different.

How many ornaments did I have, and what shape were they?

[enigma1662]

### 5 responses to “Enigma 1662: Red face?”

1. Jim Randell 4 December 2011 at 12:08 pm

The following Python program uses the mathematical combination function C(n, k) to compute the permutations where all displayed faces are different, and where exactly three objects display the same face. And then determines the solution where these numbers are in the ratio of 2:3. It runs in 30ms.

```from enigma import C, factorial, printf

# consider m objects with n faces. m <= n

# number of faces in the platonic solids
for n in (4, 6, 8, 12, 20):
for m in range(3 + 1, n + 1):
# pd = number of permutations where all displayed faces are different
pd = factorial(n, n - m)
# p3 = number of permutations where exactly 3 objects display same face
p3 = factorial(n, n - m + 2) * C(m, 3)
s = ('***SOLUTION***' if (2 * p3 == 3 * pd) else '')
printf("objects={m} faces={n} pd={pd} p3={p3} [{r:.2f}] {s}", r=float(p3) / float(pd))
```

Solution: There are 11 icosahedral ornaments.

• jimrandell 4 December 2011 at 12:09 pm

And here’s an even simpler version:

```# consider m objects with n faces. m <= n
# pd = number of permutations where all displayed faces are different
# p3 = number of permuations where exactly 3 objects display same face
# 2 * p3 == 3 * pd when m * (m - 1) * (m - 2) == 9 * (n - m + 2) * (n - m + 1)

# number of faces in the platonic solids
for n in (4, 6, 8, 12, 20):
for m in range(3 + 1, n + 1):
if m * (m - 1) * (m - 2) == 9 * (n - m + 2) * (n - m + 1):
print("objects={m} faces={n}".format(n=n, m=m))
```
2. Hugh Casement 6 May 2016 at 9:06 am

What I can’t work out is the most likely configuration.  Is it two faces the same and all the others different?  Or two of one colour and two of another, with the rest different?  Or what?  I usually get in a muddle with permutations and combinations, so would welcome any help there.

• Jim Randell 31 May 2016 at 3:50 pm

@Hugh: I’m never too confident that I’ve calculated such counting problems correctly, but I wrote a program to do 100 million random trials, selecting 11 numbers from 1 to 20.

It would seem that the mostly likely configuration is (2, 2, 1, 1, 1, 1, 1, 1, 1), i.e. one pair of objects sharing one value (colour), another pair sharing another value and all the rest having their own unique value.