Project Euler 92 - Square digit chains

Official link:

Thought Process

The largest number we are looking for is 9,999,999 which has a digit sum of 567, so if we know if 567 points to 89 (which it does) then so will 9,999,999.

Through this method I initialise an array = [0] * 568, and pre-compute where each number from 1 to 567 points to and let array[number] = 89 or 1

Then I loop through all numbers, y, from 1 to 10,000,000 and return array[square_digit_sum(y)] if this equal to 89 I add to a count. Code takes ~25 seconds, it can definitely be optimised further

I used a modified version of my digit sum function, and a secondary function that finds whether a number will end up at 89 or 1

Interactive Code

Input an integer (yourinput)

Code will output the number of numbers < yourinput will arrive at 89