This question already has an answer here:
- Generate Pascal's triangle 27 answers
the contest is already finished, so I don't think it's cheating to ask: I am trying to optimize this small contest: pascal triangle I started with 4.72 and worked myself up to 7.48. The best made a 9.05 but in perl, python2 best score is 8.25. Unfortunately they don't let you look at what others did. My current solution is the following:
l=[1]
print 1
while(len(l)<31):
print' '.join(map(str,l+[1]))
l=[1]+map(lambda x,y:x+y,l,l[1:]+[1])
Now I tried to get rid of the loop in using list comprehension, but I am too new to python to get this done. Can anyone give me a hint for nested list comprehension shortening this code further down?
Thank you for your audience.
print x
withprint' '.join(map(str,x))
for a loss of 18 bytes. – primo Mar 20 at 13:57a=[];exec"a=map(sum,zip(a,[0]+a))+[1];print a;"*input()
– primo Mar 20 at 14:28