OFFSET
0,3
REFERENCES
D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, 1969, Vol. 2, p. 189.
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
Prepared and presented by Matthew Szudzik of Wolfram Research, A Mathematica programming contest
Eric Weisstein's World of Mathematics, Negadecimal
Eric Weisstein's World of Mathematics, Negabinary
Wikipedia, Negative base
EXAMPLE
Decimal 25 is "185" in base -10 because 100 - 80 + 5 = 25.
MATHEMATICA
ToNegaBases[i_Integer, b_Integer] := FromDigits@ Rest@ Reverse@ Mod[ NestWhileList[(# - Mod[ #, b])/-b &, i, # != 0 &], b]
PROG
(Haskell)
a039723 0 = 0
a039723 n = a039723 n' * 10 + m where
(n', m) = if r < 0 then (q + 1, r + 10) else qr where
qr@(q, r) = quotRem n (negate 10)
-- Reinhard Zumkeller, Apr 20 2011
(Python)
def A039723(n):
s, q = '', n
while q >= 10 or q < 0:
q, r = divmod(q, -10)
if r < 0:
q += 1
r += 10
s += str(r)
return int(str(q)+s[::-1]) # Chai Wah Wu, Apr 10 2016
(PARI) A039723 = base(n, b=-10) = if(n, base(n\b, b)*10 + n%b, 0) \\ M. F. Hasler, Oct 16 2018 [Corrected by Jianing Song, Oct 21 2018]
CROSSREFS
KEYWORD
base,easy,nonn
AUTHOR
Robert Lozyniak (11(AT)onna.com)
STATUS
approved