Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function subtract(num1, num2)
- if 0 > num1 or 0 > num2 then return "can't subtract negative numbers sorry lol" end
- local res = ""
- local n1 = num1-num2 > 0 and num1 or num2
- local n2 = tostring( n1 == num1 and num2 or num1 )
- for i=1,#n2-1 do
- --print( n2:sub(i,i) )
- res = res .. tostring( 9 - tonumber(n2:sub(i,i)) )
- end
- res = res .. 10 - n2:sub(#n2, #n2)
- return tonumber( tostring( n1 + tonumber(res) ):sub(2, -1) ) -- where you actually add the numbers you get
- end
- -------------------------
- for i = 0, 100 do
- local x, y = math.random(1000000), math.random(1000000)
- if y>x then x,y = y,x end
- print(("-"):rep(10))
- print(string.format("%s - %s", x, y))
- print( "=> " .. subtract(x, y) )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement