Skip to content

Instantly share code, notes, and snippets.

@omaraflak
Created August 18, 2021 10:15
Show Gist options
  • Save omaraflak/2ef86e5b6c0c2ad1ae5ad4930f4c9731 to your computer and use it in GitHub Desktop.
Save omaraflak/2ef86e5b6c0c2ad1ae5ad4930f4c9731 to your computer and use it in GitHub Desktop.
Landau's Function
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