Your move() function is still outright deleting whatever's in ntable[0], even though you're using that to store information essential to the calculation. I may not've stressed this enough before, but you just can't do that! Let's run through the logic of the program to make it clear as to why.
Say you've got your two numbers, 4321 and 6932. These get converted into tables such that num[1] = 4, num[2] = 3, etc, and num2[1] = 6, num2[2] = 9, etc. Note here that the rule you're using is that the lower the index, the higher the value of the digit.
You pass these tables to your mul() function. For each digit in num2, it generates a "calc" table:
for i21 = 1, #num do
calc[i21] = num[i21] * num2[i1]
check(calc)
end
On the first iteration, calc[1] = num[1] * num2[1], which is 4 * 6 = 24. In case we've now got more then one digit stored in that index (which, as it happens, we do), this gets "checked".
Now, to go on a slight tangent, when you pass "calc" to "check()" that function gets handed a pointer to the actual "calc" table (if it were a different variable type, like a number, it'd just pass the number; with tables, you get a pointer).
It sticks that pointer in "ntable", but that variable still leads to the same table - any changes it makes to "ntable" are reflected in "calc" because the two variables literally lead to the same area of memory. This is worth mentioning, because when you call "check()" you don't actually save what it returns. The only reason it does anything is because of the way the table pointers work. "check()" could have its "return" statement removed completely and it'd work just the same. Ditto for "move()".
Anyway, "check()" notices that calc[1] exceeds ten. It hence sets calc[1] to 4, and sets the next lowest index - calc[
0] - to 2.
Then you call "move()" on that result, which spots that calc[0] isn't nil and… simply deletes it. So now your calc table consists soley of this:
calc[1] = 4
Hopefully this makes it clear what you need to do - your "move()" function currently only moves digits one way, which happens not to be the direction we need it to be in this instance.
Edit:
Bear in mind that I'm being coy; the answer is fairly simple, I just feel you should be able to spot it. ;)/>
But I suppose it's unfair not to point out that your initial attempt at the move() function
did go in both directions - it just left a dirty great string in calc[0]. "nil" isn't the same thing as nil.
Another point: Bear in mind that if, say, after moving you get a table that looks like this:
calc[1] = 2
calc[2] = 4
… the first bit of code I quoted will, on its second iteration, overwrite calc[2] with something else. You may want to rig it like this:
for i21 = 1, #num do
calc[i21] = num[i21] * num2[i1]
end
check(calc)
… which will require you to make the "check" function count backwards through the digits.