A073789 Numbers in base -8.
0, 1, 2, 3, 4, 5, 6, 7, 170, 171, 172, 173, 174, 175, 176, 177, 160, 161, 162, 163, 164, 165, 166, 167, 150, 151, 152, 153, 154, 155, 156, 157, 140, 141, 142, 143, 144, 145, 146, 147, 130, 131, 132, 133, 134, 135, 136, 137, 120, 121, 122, 123, 124, 125, 126
Offset: 0
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, Negabinary
- Wikipedia, Negative base
Programs
-
Haskell
a073789 0 = 0 a073789 n = a073789 n' * 10 + m where (n', m) = if r < 0 then (q + 1, r + 8) else (q, r) where (q, r) = quotRem n (negate 8) -- Reinhard Zumkeller, Jul 07 2012
-
Mathematica
ToNegaBases[i_Integer, b_Integer] := FromDigits[ Rest[ Reverse[ Mod[ NestWhileList[(#1 - Mod[ #1, b])/-b &, i, #1 != 0 &], b]]]]; Table[ ToNegaBases[n, 8], {n, 0, 60}]
-
Python
def A073789(n): s, q = '', n while q >= 8 or q < 0: q, r = divmod(q, -8) if r < 0: q += 1 r += 8 s += str(r) return int(str(q)+s[::-1]) # Chai Wah Wu, Apr 09 2016