-
-
Save orlp/26efd8aa77a48ad32c884d9978e7bf24 to your computer and use it in GitHub Desktop.
This file contains 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
import math | |
for n in range(1, 65): | |
valid = [ | |
(l, r) | |
for l in range(10 + math.ceil(math.log2(n + 1))) | |
for r in range(10 + math.ceil(math.log2(n + 1))) | |
if 2**l - 1 <= n and 2**r - 1 <= n and 2**l + 2**r - 1 >= n | |
] | |
cost = lambda l, r: 2**l * l + (n + 1 - 2**l) * r | |
minimal = min(cost(l, r) for l, r in valid) | |
for l, r in valid: | |
if cost(l, r) == minimal: | |
print(f"{n:2} {l:2} {r:2}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment