How can I implement the implementation of Karatsuba Multiplication? Inputs are given in a string.
This is my code
def multiply(x,y):
x_len = len(x)
y_len = len(y)
lenn= max(x_len,y_len)
len2=lenn//2
if x_len < 3 or y_len <3:
return int(x)*int(y)
else:
a= x[ : len2]
b= x[ len2 : ]
c= y[ : len2]
d= y[ len2 : ]
S1 = multiply(a,c)
S2 = multiply(b,d)
S3 = multiply(str(int(a)+int(b)) , str(int(c)+int(d)))
S4 = str(S3 - S2 - S1)
X1= S1 * 10**(lenn)
X2 = S3 * 10**(len2)
X3 = S2
return X1+X2+X3