# Enigmatic Code

Programming Enigma Puzzles

## Tantalizer 477: Precognition

From New Scientist #1028, 25th November 1976 [link]

I overheard Professor Foresight discussing the results of a small precognition test the other day. It emerged that he had tossed a penny five times, inviting the thirteen members of his class to write down what was coming before each throw. Six students had done better than the rest, all scoring the same number, although no two had produced identical lists of guesses. Nor had any two of the remaining students produced identical lists.

It also emerged that the penny had not come up Heads all five times. Nor was the actual series Head, Tail, Tail, Tail, Head. Nor was it Tail, Tail, Head, Tail, Tail. At this point the discussion broke up and I was left wondering just what the actual series was. Given that each of these series just mentioned was the guess of one of the unsuccessful seven, can you oblige?

[tantalizer477]

### 2 responses to “Tantalizer 477: Precognition”

1. Jim Randell 5 July 2017 at 9:47 am

Six students scored better than the remaining seven, and they all had different sequences of guesses.

There’s only one way to get all 5 outcomes wrong (or right, C(5, 0) = C(5, 5) = 1), and only 5 ways to get exactly one outcome wrong (or right, C(5, 1) = C(5, 4) = 5).

So it follows that six of the students got 3 right (C(5, 2) = C(5, 3) = 10) and seven of them got at most 2 right (at least 3 wrong).

This Python program runs in 43ms.

```from itertools import product
from enigma import printf

# sequences mentioned
seqs = ( 'HHHHH', 'HTTTH', 'TTHTT' )

# count the matches in two sequences
def match(s1, s2):
return sum(a == b for (a, b) in zip(s1, s2))

# choose the sequence
for s in product('HT', repeat=5):
# each of the mentioned sequences scores less than 3
if all(match(s, x) < 3 for x in seqs):
printf("seq = {s}")
```