Ad

add

add=lambda a,b:a+b
Fundamentals
Mathematics
Code
Diff
  • def m(a, b):
        # Did you know? This is an implementation of Long Multiplacation
        negative_result = (a < 0) ^ (b < 0)
        a, b = abs(a), abs(b)
        a_str = str(a)[::-1]
        b_str = str(b)[::-1]
        result_length = len(a_str) + len(b_str)
        result = [0] * result_length
        for i in range(len(a_str)):
            for j in range(len(b_str)):
                digit_a = int(a_str[i])
                digit_b = int(b_str[j])
                product = digit_a * digit_b
                result[i + j] += product
                carry = result[i + j] // 10
                result[i + j] %= 10
                result[i + j + 1] += carry
        while len(result) > 1 and result[-1] == 0:
            result.pop()
        result_str = ''.join(map(str, result[::-1]))
        final_result = int(result_str)
        return -final_result if negative_result else final_result
    
    # test me pls
    • m = __import__('operator').mul
    • def m(a, b):
    • # Did you know? This is an implementation of Long Multiplacation
    • negative_result = (a < 0) ^ (b < 0)
    • a, b = abs(a), abs(b)
    • a_str = str(a)[::-1]
    • b_str = str(b)[::-1]
    • result_length = len(a_str) + len(b_str)
    • result = [0] * result_length
    • for i in range(len(a_str)):
    • for j in range(len(b_str)):
    • digit_a = int(a_str[i])
    • digit_b = int(b_str[j])
    • product = digit_a * digit_b
    • result[i + j] += product
    • carry = result[i + j] // 10
    • result[i + j] %= 10
    • result[i + j + 1] += carry
    • while len(result) > 1 and result[-1] == 0:
    • result.pop()
    • result_str = ''.join(map(str, result[::-1]))
    • final_result = int(result_str)
    • return -final_result if negative_result else final_result
    • # test me pls