Java 8, 77 93 74 71 69 bytes
int n=1111;int m=1;while(x>m++){n=Integer.parseInt((n*n+"").substring(0,4));}
x->{int n=1111;int m=1;while(x>m++){n=Integer.parseInt((n*n+"").substring(0,4));}return n;}
x->{int n=1111;for(;--x>0;){n=Integer.parseInt((n*n+"").substring(0,4));}}
x->{long n=1111;for(;--x>0;){n=Long.valueOf((n*n+"").substring(0,4));}}
x->{long n=1111;for(;--x>0;)n=Long.valueOf((n*n+"").substring(0,4));}
Each repetition makes n
the first 4 characters of n*n
.
Post history:
77 bytes: initial code (incomplete)
+16 bytes, by Olivier Grégoire: completed code by making it a Lambda function.
-19 bytes: replace
while
withfor
cycle.-4 bytes: used
long
s instead ofint
s-2 bytes, by Roman Gräf: removed unnecessary brackets
Thanks to @OlivierGrégoire and @RomanGräf for pointing out some issues!
Wait, Java beats... (drumroll) Clojure and Matlab here! A big applause to Java please!