-5
0
I'm solving problem: in file "a.in" given the number N - length of the number consists of ones. Need to gets square of it, and put this in file "a.out". This is my shortest solution(150 bytes):
char s[1<<27];j;main(i,n){for(fscanf(fopen("a.in","r"),"%d",&n),i=n*=2;--i;j+=i<n/2?i:n-i,s[i-1]=48+j%10,j/=10);fprintf(fopen("a.out","w"),"%s\n",s);}
This is formated copy:
char s[1<<27];j;
main(i,n){
for(fscanf(fopen("a.in","r"),"%d",&n),i=n*=2;--i;
j+=i < n/2 ? i: n-i,
s[i - 1] = 48 + j % 10,
j /= 10
);
fprintf(fopen("a.out","w"),"%s\n",s);
}
The best solution of this problem has size 131 bytes, how? Valid languages: C, C#, C++, Pascal, Java.
3Maybe I'm a bit slow, but it took me a long time just to get what the program should do. If the number is 3, you want to print 111*111, which is 12321. Right? – ugoren – 2012-02-26T21:12:28.943
3What's the source of this puzzle? – Peter Taylor – 2012-02-27T15:45:22.417
8Why the restriction to such a few languages? – user unknown – 2012-03-15T03:26:03.300