Skip to content

Instantly share code, notes, and snippets.

View madslyng's full-sized avatar
💭
🚜 Having fun in Big Agro 🌱

Mads Lyng madslyng

💭
🚜 Having fun in Big Agro 🌱
  • Aarhus, Denmark
View GitHub Profile
@anirudhjayaraman
anirudhjayaraman / karatsuba.py
Last active September 11, 2023 10:18
Karatsuba Multiplication
def karatsuba(x,y):
"""Function to multiply 2 numbers in a more efficient manner than the grade school algorithm"""
if len(str(x)) == 1 or len(str(y)) == 1:
return x*y
else:
n = max(len(str(x)),len(str(y)))
nby2 = n / 2
a = x / 10**(nby2)
b = x % 10**(nby2)