Skip to content

Instantly share code, notes, and snippets.

@ahmed4end
Created August 19, 2020 15:22
Show Gist options
  • Save ahmed4end/e0121243e160129b63fa965715c85907 to your computer and use it in GitHub Desktop.
Save ahmed4end/e0121243e160129b63fa965715c85907 to your computer and use it in GitHub Desktop.
fint powers of two less than n.
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