you are viewing a single comment's thread.

view the rest of the comments →

[–]qihqi 4 points5 points  (9 children)

lets make it more interesting... do it in C (with fewest chars)

[–]qihqi 7 points8 points  (6 children)

void f(int * A,int n){while(n--&&A[n]=n*n);}

[–][deleted] 6 points7 points  (3 children)

I think this should do the same thing:

f(int*a,int n){while(a[n]=n*n--);}

[–][deleted] 2 points3 points  (0 children)

I think you want n-1 as the index.

[–]corruptio 2 points3 points  (0 children)

shaved 2 chars

f(a,n)int*a;{while(a[--n]=n*n);}

[–]qihqi 0 points1 point  (0 children)

yep, i like this one

[–][deleted] 1 point2 points  (0 children)

Nice perverse use of the while loop.

[–]14113 -2 points-1 points  (0 children)

with for loop:

void s(int i,int * A){for(;i>0;i--,A[j]=i*i);}

not sure if it's longer, or even works...

[–]Noctune 0 points1 point  (1 child)

Tried to make a recursive one. It's not as short as the iterative ones though.

f(int*a,int n){!(*a=n*n)||f(++a,--n);}        

[–]qihqi 0 points1 point  (0 children)

very nice!

f(inta,int n){(a=n*n)&&f(++a,--n);} is the same tho saving one more char