LogoWCF

Day 24: Elf Numbers

Santa and the elves are doing the last of the preparations getting ready to set off into the sky tonigh. As they get ready the ordering of the elves going through the halls is important to keep order and so nothing gets mixed up.

Elves use a system of numbering creatively called Elf Numbers. There is a formula mapping regular natural numbers to elf numbers. For each digit of a natural number put it through the following formula and add up all the results for each digit. Then repeat that process over and over again. If the sum is ever equal to 0 then the number is an Elf number. If the sum never reaches 0 then it is not an Elf Number.

The formula is:

Here’s the first 10 numbers put through the formula once.

00
18
20
30
432
5120
6288
7560
8960
91512

Taking 4 as an example through the full process:

Taking 8 as an example through the full process:

Therefore 4 is an Elf Number and 8 will never terminate so it is not an Elf Number.

Problem: It’s imperative that Santa knows the sum of the first 50,000 Elf Numbers. Report back to Santa as soon as you get the results.

Hint If there is a cycle in the chain when processing the numbers before reaching 0 then you know it won't be an Elf Number.

Solutions