Sfida:
Nel linguaggio di programmazione di tua scelta, accetta un numero intero come input nella base 10 e lo emette nella notazione negativa , che è anche nota come base -10
Algoritmo di esempio:
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
Ovviamente, puoi usare qualsiasi algoritmo, purché soddisfi la sfida
Esempi di ingressi / uscite:
Ingresso:
12
Produzione:
192
Un altro esempio:
Ingresso:
2048
Produzione:
18168
Regola:
Non è necessario utilizzare alcun metodo integrato che risolva questo problema esistente nel linguaggio di programmazione
Questo è un codice-golf , quindi vince il codice più corto!
[0, 1, 8, 1, 6, 8]un output accettabile per l'input 2048?