Skip to content

Instantly share code, notes, and snippets.

@tomerfiliba
Created May 14, 2012 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomerfiliba/2693796 to your computer and use it in GitHub Desktop.
Save tomerfiliba/2693796 to your computer and use it in GitHub Desktop.
The most efficient way to compute powers of two!
>>> x=""
>>> for i in range(25):
... print i, len(x)
... x = repr(x)
...
0 0
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
9 512
10 1024
11 2048
12 4096
13 8192
14 16384
15 32768
16 65536
17 131072
18 262144
19 524288
20 1048576
21 2097152
22 4194304
23 8388608
24 16777216
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment