cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-2 of 2 results.

A072137 Length of the preperiodic part of the 'Reverse and Subtract' trajectory of n.

Original entry on oeis.org

0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 6, 4, 5, 3, 3, 5, 4, 6, 2, 1, 2, 1, 2, 6, 4
Offset: 0

Views

Author

Klaus Brockhaus, Jun 24 2002

Keywords

Comments

'Reverse and Subtract' (cf. A070837, A070838) is defined by x -> |x - reverse(x)|, where reverse(x) is the digit reversal of x.
For every n the trajectory eventually becomes periodic, since 'Reverse and Subtract' does not increase the number of digits and so the set of available terms is finite. For small n the period length is 1, the periodic part consists of 0's, the last term of the preperiodic part is a palindrome.
The first n with period length 2 and a nontrivial periodic part is 1012 (cf. A072140).
This sequence is a weak analog of A033665, which uses 'Reverse and Add'.

Examples

			a(15) = 4 since 15 -> |15- 51| = 36 -> |36 - 63| = 27 -> |27 - 72| = 45 -> |45 - 54| = 9.
		

Crossrefs

Programs

  • Haskell
    import Data.List(inits, find); import Data.Maybe(fromJust)
    a072137 :: Int -> Int
    a072137 = length . fst . spanCycle (abs . a056965) where
       spanCycle :: Eq a => (a -> a) -> a -> ([a],[a])
       spanCycle f x = fromJust $ find (not . null . snd) $
                                  zipWith (span . (/=)) xs $ inits xs
                       where xs = iterate f x
    -- Reinhard Zumkeller, Oct 24 2010
  • Mathematica
    a[n_] := (k = 0; FixedPoint[ (k++; Abs[# - FromDigits[ Reverse[ IntegerDigits[#] ] ] ]) &, n]; k - 1); Table[ a[n], {n, 0, 104}] (* Jean-François Alcover, Dec 01 2011 *)

A070837 Smallest number k such that abs(k - R(k)) = 9n, where R(k) is digit reversal of k (A004086); or 0 if no such k exists.

Original entry on oeis.org

10, 13, 14, 15, 16, 17, 18, 19, 90, 1011, 100, 0, 0, 0, 0, 0, 0, 0, 0, 1021, 1090, 103, 0, 0, 0, 0, 0, 0, 0, 1031, 1080, 0, 104, 0, 0, 0, 0, 0, 0, 1041, 1070, 0, 0, 105, 0, 0, 0, 0, 0, 1051, 1060, 0, 0, 0, 106, 0, 0, 0, 0, 1061, 1050, 0, 0, 0, 0, 107, 0, 0, 0, 1071, 1040, 0, 0, 0, 0, 0
Offset: 1

Views

Author

Amarnath Murthy, May 12 2002

Keywords

Comments

If 9n < 1000, k has at most 5 digits, and abs(k - R(k)) = 9n, then 10 must divide n. - Sascha Kurz, Jan 02 2003

Crossrefs

Programs

  • Mathematica
    a = Table[0, {50}]; Do[d = Abs[n - FromDigits[ Reverse[ IntegerDigits[n]]]] / 9; If[d < 51 && a[[d]] == 0, a[[d]] = n], {n, 1, 10^7}]; a
  • Python
    def back_difference(n):
        r = int(str(n)[::-1])
        return abs(r-n)
    def a070837(n):
        i = 0
        while True:
            if back_difference(i)==9*n:
                return i
            i+=1
    # Christian Perfect, Jul 23 2015

Extensions

More terms from Sascha Kurz, Jan 02 2003
a(21) corrected by Christian Perfect, Jul 23 2015
Showing 1-2 of 2 results.