Challenge:
In the programming language of your choice, accept an integer as input in base 10, and output it in the negadecimal notation, which is also known as base -10
Example algorithm:
This is an algorithm taken from Wikipedia to convert base 10 to any negative base in VB.NET:
Function toNegativeBase(Number As Integer , base As Integer) As System.Collections.Generic.List(Of Integer)
Dim digits As New System.Collections.Generic.List(Of Integer)
while Number <> 0
Dim remainder As Integer= Number Mod base
Number = CInt(Number / base)
if remainder < 0 then
remainder += system.math.abs(base)
Number+=1
end if
digits.Insert(0, remainder)
end while
return digits
end function
Obviously, you can use any algorithm, as long as it fulfills the challenge
Example inputs / outputs:
Input:
12
Output:
192
Another example:
Input:
2048
Output:
18168
Rule:
You must not use any built-in methods that solve this problem that exist in your programming language
This is a code-golf, so shortest code wins!
[0, 1, 8, 1, 6, 8]
be an acceptable output for input2048
? \$\endgroup\$