project-euler

Square digit chains

Problem Description

A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before.

For example,

  44 โ†’ 32 โ†’ 13 โ†’ 10 โ†’ 1 โ†’ 1
  85 โ†’ 89 โ†’ 145 โ†’ 42 โ†’ 20 โ†’ 4 โ†’ 16 โ†’ 37 โ†’ 58 โ†’ 89

Therefore any chain that arrives at 1 or 89 will become stuck in an endless loop. What is most amazing is that EVERY starting number will eventually arrive at 1 or 89.

How many starting numbers below ten million will arrive at 89?

Performance

________________________________________________________
Executed in   25.55 secs    fish           external
   usr time   25.40 secs    0.08 millis   25.40 secs
   sys time    0.22 secs    1.38 millis    0.22 secs