Created
August 19, 2020 15:22
-
-
Save ahmed4end/e0121243e160129b63fa965715c85907 to your computer and use it in GitHub Desktop.
fint powers of two less than n.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = 50 | |
prev = lambda n: [i for i,j in enumerate(bin(n)[:1:-1]) if int(j)][::-1][0] | |
powers = lambda x, t=[]: t+[1] if prev(x)==1 else powers(2**prev(x) - 1, t+[prev(x)]) | |
print(powers(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment