Table of Contents
This is a simple PHP script designed to both refresh my knowledge of PHP in addition to serving as an assessment for potential employers.
It takes all the integers from a specified number down to 1 and checks to see how many of them reduce to 89 using a "squared digits" algorithm.
The "squared digits" algorithm means that the digits of each number are individually squared, then summed together to reach a new number. The algorithms continue this process with each new number derived.
There are two algorithms, each results in a different count at the end.
The "get_repeating_val" stays true to the spirit of the assignment in that it returns the first value that repeats during the loop. Although this is more technically correct, it does not lead to the assignment's expected counts at the end, thus the need for the other algorithm,
The "get_looping_val" algorithm searches for the first instance of "89" or "1" in the loop and (rightfully) assumes that it will eventually loop back to that number again, so it immediately returns that number.
This algorithm eventually leads to the correct counts as defined in the initiall assignment.
As this is a simple PHP script, the best way to use it is by running it in your favorite IDE.
Distributed under the ISC License. See LICENSE.txt
for more information.
Chris McGee - @SturmB - [email protected]
Project Link: https://github.com/SturmB/squared-digits