Created
August 18, 2021 10:15
-
-
Save omaraflak/2ef86e5b6c0c2ad1ae5ad4930f4c9731 to your computer and use it in GitHub Desktop.
Landau's Function
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
from math import gcd | |
from functools import reduce | |
from typing import Iterator | |
def lcm(nums: list[int]) -> int: | |
_lcm = lambda a, b: (a * b) // gcd(a, b) | |
return reduce(_lcm, nums) | |
def partitions(n: int, s: int = 1) -> Iterator[int]: | |
yield (n,) | |
for i in range(s, n // 2 + 1): | |
for p in partitions(n - i, i): | |
yield (i,) + p | |
def landau(n: int) -> int: | |
return max(lcm(p) for p in partitions(n)) | |
for i in range(1, 50): | |
print(f"g({i})={landau(i)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment