f=lambda n:[0][n:]or[i+j*2for i in 0,1for j in f(n-1)] for n in range(4): print '%d -> %s' % (n,f(n))
Standard input is empty
0 -> [0] 1 -> [0, 1] 2 -> [0, 2, 1, 3] 3 -> [0, 4, 2, 6, 1, 5, 3, 7]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!