about:drewcsillag

Musings of a programmer, musician, photographer, and Christian.

Python Fun - Onliners

I’ve not done a ton of programming in Python for a while, but I still do like the language. I also like trying to do things in one line (ok, one statement), just because it’s a bit more difficult :). These are pretty old, but I used to keep these in my email signature line…

Mandlebrot set

1
2
3
4
#this one really only works if your terminal window is 80 wide
import os;map(lambda i:os.write(1,chr(reduce(lambda(z,t),o:abs(z*z)>4and(6,
t)or(z*z+o[0],t+1),[(i%80*.04875-2.6+i/80*2.8j/26-1.4j,65)]*31)[1])),range
(2080))

The screen of e

1
2
print'e=%s'%(lambda x:'%s.%s'%(x[0],x[1:-1]))(str(reduce(lambda
(a,b),y,z=10L**1835:(a+z/b,b*y),[[0L,1L]]+range(1,752))[0]))

When is easter?

1
2
3
4
5
print(lambda(m,d):'%s %s'%({3:'March',4:'April'}[m],d))((lambda(m,d):(m
==3and d>31)and(4,d-31)or(m,d))((lambda(m,d,y):(m,d+7-(lambda(m,d,y):(23
*m/9+d+4+y/4-y/100+y/400)%7)(m<3and(m,d+y,y-1)or(m,d+(y-2),y))))((lambda
(p,y):(p>31)and(4,p-31,y)or(3,p,y))((lambda y:(50-((11*((y%19)+1)-y/100+
(y/100)/4+(8*(y/100+11)/25))%30),y))(int(raw_input('year>')))))))

How much is your loan payment?

1
2
print(lambda(q,p):'pmt:$%0.2f'%(q*p/(p-1)))((lambda(a,r,n),t:(a*r/
t,pow(1+r/t,n*12)))(map(input,('amt:','%rate:','years:')),1200.0))

Comments