31 lines
1 KiB
Text
31 lines
1 KiB
Text
F add_with_carry(&result, =addend, =addendpos)
|
||
L
|
||
L result.len < addendpos + 1
|
||
result.append(‘0’)
|
||
V addend_result = String(Int(addend) + Int(result[addendpos]))
|
||
V addend_digits = Array(addend_result)
|
||
result[addendpos] = addend_digits.pop()
|
||
|
||
I addend_digits.empty
|
||
L.break
|
||
|
||
addend = addend_digits.pop()
|
||
addendpos++
|
||
|
||
F longhand_multiplication(multiplicand, multiplier)
|
||
[Char] result
|
||
L(multiplicand_digit) reversed(multiplicand)
|
||
V multiplicand_offset = L.index
|
||
L(multiplier_digit) reversed(multiplier)
|
||
V multiplier_offset = L.index + multiplicand_offset
|
||
V multiplication_result = String(Int(multiplicand_digit) * Int(multiplier_digit))
|
||
|
||
L(result_digit_addend) reversed(multiplication_result)
|
||
V addend_offset = L.index + multiplier_offset
|
||
add_with_carry(&result, result_digit_addend, addend_offset)
|
||
|
||
result.reverse()
|
||
R result.join(‘’)
|
||
|
||
V sixtyfour = ‘18446744073709551616’
|
||
print(longhand_multiplication(sixtyfour, sixtyfour))
|