Here’s a program one of my friends challenged me to make. It basically takes two positive integers and multiplies them like a human would do it, digit by digit, carrying the one, etc. It’s not very useful, since it’s probably running in order n^2 or n! time, but it does have the advantage that it doesn’t end up using scientific notation, so it’s extremely accurate. I’m thinking of adding someting to do numbers with decimal points, but I might not, so I’m posting it now. Any suggestions on making it faster would be very much appreciated!

```
set {num1, num2} to {1234, 5678} --The two numbers to multiply
set {num1, num2} to {num1 as text, num2 as text}
set totallist to {}
repeat with i from 1 to length of num2
set bottomnum to (character (-1 * i) of num2 as number) --Take the first digit on the right of the first number
set total to 0 --This is the total for the first digit
repeat with j from 1 to length of num1 --Multiply it by each digit of the other number
set topnum to (character (-1 * j) of num1 as number)
set total to add((topnum * bottomnum) & zeroes(i + j - 2) as text, total)
end repeat
set end of totallist to (total as text) --This list has each digit's totals
end repeat
set resul to ""
repeat with k in totallist
set resul to add(contents of k, resul) --Add the list together
end repeat
repeat until character 1 of resul is not "0"
set resul to text 2 thru end of resul --Remove any stray leading zeroes
end repeat
return resul
to add(int1, int2) --Add two numbers "by hand"
set addplace to 0 --For carrying the one
set {int1, int2} to {"0" & int1 as text, "0" & int2 as text}
if length of int1 â‰ length of int2 then --make both strings the same length by adding zeroes
if length of int1 < length of int2 then repeat until length of int1 = length of int2
set int1 to "0" & int1
end repeat
if length of int1 > length of int2 then repeat until length of int1 = length of int2
set int2 to "0" & int2
end repeat
end if
set res to ""
repeat with i from 1 to length of int1
set i to -i --So we go from right to left
set a to (character i of int1 as number) + (character i of int2 as number) + addplace as text
set res to (character -1 of a) & res
if length of a > 1 then
set addplace to 1
else
set addplace to 0
end if
end repeat
return res
end add
to zeroes(num) --To easily multiply things by ten by adding zeroes
set res to ""
repeat num times
set res to res & "0"
end repeat
return res
end zeroes
```

EDIT: In case anyone was wondering just how freakishly accurate this thing can get, 2^1024 - 1 (The largest number allowed before overflow on my version of AS) is 17976931348623159077293051907890247336179769789423065727343008115773267580550096313270847732240753602112011387987

1393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342

462881473913110540827237163350510684586298239947245938479716304835356329624224137215. This took quite a while to compute and is about 1.79E+308, if you’re wondering.