Keep the code that does the positive stuff and throw out the code that does the negative stuff.
Now, the only difference between, say -100 and 100 is that one is multiplied by -1, right?
The same applies to the resulting sequence:
100 == 81 + 27 - 9 + 1
(-1)100 == (-1)(81 + 27 - 9 + 1)
-100 == -81 - 27 + 9 - 1
So, when you start, check to see if the number is < 0 (meaning that it is negative). (Make sure to remember that in a variable somewhere.) If it is, negate the number (making it positive), run it through the algorithm, and remember that every time you want to put a '+' make it '-' instead, and every time you want to put a '-' put a '+' instead.
But I tried to find where exactly my code works with a negative value and I tried to change it but it didn't work.
Can you please see where exactly my code works with negative values? The way I built it is not just dealing with positive or negative integer. I guess it's more complicated than this.