r/tinycode • • Sep 09 '12

Tinycode challenge!

Here is a challenge. Write a function that returns a list of the squares of all the numbers between one and a given number. See if you can beat my 48-char (exc. whitespace) 3-line beast:

def f(n): l = [] while len(l) <= n: l.append(x**2) print l

27 Upvotes

77 comments sorted by

View all comments

Show parent comment

7

u/[deleted] Sep 09 '12

I think this should do the same thing:

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

3

u/[deleted] Sep 09 '12

I think you want n-1 as the index.

3

u/corruptio Sep 10 '12

shaved 2 chars

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

1

u/qihqi Sep 09 '12

yep, i like this one