Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
clean primitives solution in Clear category for "Lunar" Multiply by juestr
from functools import partial
def lunar_multiply(a: int, b: int) -> int:
def add(a: str, b: str) -> str:
a = a.rjust(len(b), "0")
b = b.rjust(len(a), "0")
return "".join(map(max, a, b))
def mul(a: str, b: str) -> str:
acc = ""
for bdigit in str(b):
a_m_bdigit = "".join(map(partial(min, bdigit), a))
acc = add(acc + "0", a_m_bdigit)
return acc
return int(mul(str(a), str(b)))
Aug. 29, 2023