RosettaCodeData/Task/Long-multiplication/EasyLang/long-multiplication.easy

34 lines
666 B
Text
Raw Permalink Normal View History

2024-10-16 18:07:41 -07:00
func[] bnmul a[] b[] .
2023-07-01 11:58:00 -04:00
len r[] len a[] + len b[]
2024-10-16 18:07:41 -07:00
for ia = 1 to len a[]
2023-07-01 11:58:00 -04:00
h = 0
2024-10-16 18:07:41 -07:00
for ib = 1 to len b[]
h += r[ia + ib - 1] + b[ib] * a[ia]
r[ia + ib - 1] = h mod 10000000
h = h div 10000000
2023-07-01 11:58:00 -04:00
.
2024-10-16 18:07:41 -07:00
r[ia + ib - 1] += h
2023-07-01 11:58:00 -04:00
.
2024-10-16 18:07:41 -07:00
while r[$] = 0
len r[] -1
.
return r[]
.
func$ str bn[] .
s$ = bn[$]
for i = len bn[] - 1 downto 1
h$ = bn[i]
s$ &= substr "0000000" 1 (7 - len h$) & h$
.
return s$
.
func[] bn s$ .
i = len s$ - 7 + 1
while i >= -5
r[] &= number substr s$ i 7
i -= 7
2023-07-01 11:58:00 -04:00
.
2024-10-16 18:07:41 -07:00
return r[]
2023-07-01 11:58:00 -04:00
.
2024-10-16 18:07:41 -07:00
print str bnmul bn "18446744073709551616" bn "18446744073709551616"