You are given a nonary (base 9) non-negative integer consisting of the digits 0 through 8 as usual. However the number of digits in this number (with no leading zeros) is a prefect square.
Because of this, the number can be arranged in a square grid (with the reading order still preserved).
Example with 1480 (1125 base 10):
Now let every digit in such a nonary grid indicate a motion to another grid space (with periodic boundary conditions):
432 501 678
This is saying that
0 = stay still 1 = move right 2 = move right and up 3 = move up ... 8 = move right and down
So, if in the 1480 grid you start at the 4, you then move up (remember pbc) and left to the 8, which means you move right and down back to the 4, starting a cycle with period 2.
In general this process is continued until you get to a 0 or a cycle is noticed. (A 0 is considered a cycle with period 1.)
In the case of 1480, the period eventually reached at each of the 4 starting digits is
2 2 2 1 respectively.
For a larger grid these numbers might be larger than 8, but we can still use them as "digits" in a new nonary number (simply the coefficients of 9^n as if they were digits):
2*9^3 + 2*9^2 + 2*9 + 1 = 1639 (base 10) = 2221 (base 9)
We will call this the strength of the original nonary number. So the strength of 1480 is 1639 (base 10) or, equivalently, 2221 (base 9).
Write the shortest program that tells whether the strength of a nonary number is greater than, less than, or equal to the nonary number itself. (You do not necessarily need to compute the strength.)
The input will be a non-negative nonary number that contains a square number of digits (and no leading zeros besides the special case of 0 itself). It should come from the command line or stdin.
The output should go to stdout as:
G if the strength is larger than the original number (example: 1480 -> strength = 2221) E if the strength is equal to the original number (example: 1 -> strength = 1) L if the strength is less than the original number (example: 5 -> strength = 1)
Fun Bonus Challenge:
Whats the highest input you can find that is equal to its strength? (Is there a limit?)