# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1288: How many a’s here?

From New Scientist #2446, 8th May 2004 [link]

Consider the two sentences: “The number of a’s in this sentence is one” and “The number of e’s in this sentence is seven”. The first of those sentences is true and the second is false. We consider all the possible sentences of the form of those two sentences with any of the 26 letters of the alphabet in place of a and e and any word for a number between 1 and 20, inclusive, at the end of the sentence. So we are looking at 26 × 20 = 520 sentences in all.

How many of these sentences are true?

Note: I am waiting for a phone line to be connected at my new house, so I only have sporadic access to the internet at the moment. The latest estimate is that I’ll have a connection by the end of October 2014.

[enigma1288]

### 4 responses to “Enigma 1288: How many a’s here?”

1. Jim Randell 8 October 2014 at 11:25 am

Programatically it is easy to construct all 520 sentences and count those that are true.

This Python program runs in 30ms.

```from enigma import irange, int2words, printf

t = 0
for n in irange(1, 20):
w = int2words(n)
for x in 'abcdefghijklmnopqrstuvwxyz':
s = "the number of " + x + "'s in this sentence is " + w
if s.count(x) == n:
t += 1
printf("[{t}: {s}]")
printf("total = {t} sentences")
```

Solution: 28 of the sentences are true.

2. Jim Olson 9 October 2014 at 2:11 am

This is not a difficult enigma conceptually but I am getting 29 true statements : h has no true statement;i,r,s and w each has two correct statements and the rest of the alphabet each has one correct statement for a total of 29 correct statements. Please point out where I have gone astray.

3. Jim Randell 9 October 2014 at 11:59 am

Here’s an analytical solution.

Counting the letters in the partial sentence: “The number of _’s in this sentence is _”. We get the following categories:

5 = e
4 = n, s
3 = i, t
2 = h
1 = b, c, f, m, o, r, u
0 = a, d, g, j, k, l, p, q, v, w, x, y, z

If we now consider completing the sentence by adding a letter (so the count will always be at least 1) and a number as a word:

For the number “one” the sentence can only be true for letters in category 0 that don’t appear in “one” (which is all of them): a, d, g, j, k, l, p, q, v, w, x, y, z (13 letters).

For “two” the sentence can be true for letters in category 1 that don’t appear in “two”: b, c, f, m, r, u (6 letters), or letters in category 0 that appear in “two” once: w (1 letter).

For “three” we need letters in category 2 but not in “three”: (0 letters), or letters in category 1 that appear in “three” once: r (1 letter), or letters in category 0 that appear in “three” twice: (0 letters).

For “four” we need letters in category 3 but not in “four”: i, t (2 letters) or letters in category 2 that appear in “four” once: (0 letters).

For “five” we need letters in category 4 but not in “five”: n, s (2 letters) or letters in category 3 that appear in “five” once: i (1 letter).

For “six” we need letters in category 5 but not in “six”: e (1 letter) or letters in category 4 that appear in “six” once: s (1 letter).

For “seven” there is no category 6 so we only need to look for letters in category 5 that appear in “seven” once: (0 letters), or letters in category 4 that appear in “seven” twice (0 letters).

Higher numbers don’t add enough letters to allow us to look in category 5 or less.

So the grand total is that 28 of the sentences are true.