### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,270)
- misc (3)
- project euler (2)
- puzzle (67)
- site news (50)
- tantalizer (69)
- teaser (7)

### Site Stats

- 206,369 hits

Programming Enigma Puzzles

26 November 2018

Posted by on **From New Scientist #1627, 25th August 1988** [link]

Kugelbaum wandered into a history lecture by mistake and, almost as quickly, but not by mistake, wandered out again. “1210 may well have been a dull year,” he said to himself, “but it’s an interesting number. The first digit gives the number of 0s in it, the next the number of 1s in it, the next the number 2s in it and so on, quite consistently, right up to the very last digit. And there are other such numbers too, such as 2020 and 3211000! Curiously, I can’t find one with six digits, though.”

As he sought vainly the room where he was to give his lecture on number theory he amused himself by calculating

allthe numbers having this property. “I wonder,” he remarked as he looked into broom cupboard, “if one were to take all the numbers having this property and add them together, what the result would be?”What is the sum of

allthe numbers having the property that their first digit gives the number of 0s in the number, the next the number of 1s in the number, the next the number of 2s in the number and so on, consistently right through to and including the last digit of the number?(Since 10, 11, 12 and so on are not digits, any such number containing more than 10 digits must have zeros in its 11th place and any other places after this).

**Note:** The original puzzle statement gave 211000 as an example, not 3211000.

[enigma476]

%d bloggers like this:

[See also:

Enigma 163,Enigma 1143,Enigma 298]The

autobiographical numbersare also known as thecurious numbers, hence the title of the puzzle.I wrote some code to generate

autobiographical sequences, which is a sequence where the element at indexncounts the total number of occurrences of the elementnin the entire sequence.An autobiographical sequence represents an autobiographical number (in base 10), if all the elements have values that represent digits (i.e. are 0 – 9), and any element at an index higher than 9 is zero.

As 9 is the largest value we can have at element 0, and any elements beyond index 9 must be zero, so all decimal autobiographical numbers must have fewer than 20 digits.

This Python 3 program generates autobiographical sequences and totals the ones that correspond to decimal autobiographical numbers.

It runs in 739ms.

Run:[ @repl.it ]Solution:The total of all such numbers is 10109876341430.The full list of decimal autobiographical numbers is:

It turns out that the only autobiographical sequences with length less than 7 are:

and for

k ≥ 7there is one autobiographical sequence of lengthk:where the floating 1 is at index

k – 4and the remaining elements are 0.We can write a routine that uses this information to generate autobiographical sequences much faster than my original program.

See: [ OEIS A138480 ] [ https://en.wikipedia.org/wiki/Self-descriptive_number ]