Two's Complement Subtraction

How computers do subtraction by doing addition

Enter a substraction by yourself

-

Or generate a random subtraction

How many random digits should be generated



Do not generate a number starting with 0

HELP : You can choose to either input your own subtraction, or to let the computer do that for you by clicking the "Generate a random subtraction" button (you will need to input the number of digits that the computer will generate)
This algorithm will not work with negative numbers



QUICK REMINDER

x - y is where x is the minuend and y the subtrahend
Here, is the minuend and the subtrahend


STEP 1

Split the digits of the subtrahend


STEP 2

Take each digit and subtract it of 9, except for the last digit, subtract it of 10


STEP 3

Join the digits back together


STEP 4

Add the minuend to the transformed subtrahend


STEP 5

Remove the first digit


STEP 6

And there you have it !
You can check just to be sure :)


CREDITS

MinutePhysics for providing an awesome coding challenge
Find his video here

The Stack Overflow community for helping me out in my first version
Find the first version here