f=lambda n,k=1:n and-~f(n-(k+(k&-k)&k>0),k+1) print map(f, range(1, 21))
Standard input is empty
[5, 9, 10, 11, 13, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 29, 33, 34, 35, 36]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!