29
3
Each term in the squaring sequence, xn, is created by taking xn-1, squaring it, and removing all but the first four digits.
The sequence always begins with x1 = 1111. Squaring this yields 1234321, so x2 = 1234
The first few terms are:
1111
1234
1522
2316
5363
...
The Challenge
Your task is to, given a non-negative integer n, calculate xn. You may submit a full program which performs I/O, or a function which takes n as a parameter.
Your solution can be zero or one indexed, as long as you specify which.
Because all the terms in this sequence are shorter than 5 digits, your code should be as short as possible too. Standard code-golf loopholes apply.
May the best golfer win!
Test Cases
Note: These are 1-indexed.
1 -> 1111
8 -> 6840
15 -> 7584
20 -> 1425
80 -> 4717
2
Here's a related link :)
– FlipTack – 2016-12-02T18:56:50.287