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.

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

This page as a plain text file.
%I A072137 #18 Jun 20 2018 01:32:24
%S A072137 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,
%T A072137 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,
%U A072137 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
%N A072137 Length of the preperiodic part of the 'Reverse and Subtract' trajectory of n.
%C A072137 'Reverse and Subtract' (cf. A070837, A070838) is defined by x -> |x - reverse(x)|, where reverse(x) is the digit reversal of x.
%C A072137 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.
%C A072137 The first n with period length 2 and a nontrivial periodic part is 1012 (cf. A072140).
%C A072137 This sequence is a weak analog of A033665, which uses 'Reverse and Add'.
%H A072137 R. Zumkeller, <a href="/A072137/b072137.txt">Table of n, a(n) for n = 0..10000</a>
%e A072137 a(15) = 4 since 15 -> |15- 51| = 36 -> |36 - 63| = 27 -> |27 - 72| = 45 -> |45 - 54| = 9.
%t A072137 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 *)
%o A072137 (Haskell)
%o A072137 import Data.List(inits, find); import Data.Maybe(fromJust)
%o A072137 a072137 :: Int -> Int
%o A072137 a072137 = length . fst . spanCycle (abs . a056965) where
%o A072137    spanCycle :: Eq a => (a -> a) -> a -> ([a],[a])
%o A072137    spanCycle f x = fromJust $ find (not . null . snd) $
%o A072137                               zipWith (span . (/=)) xs $ inits xs
%o A072137                    where xs = iterate f x
%o A072137 -- _Reinhard Zumkeller_, Oct 24 2010
%Y A072137 Cf. A033665, A070837, A070838, A072138, A072139, A072140, A072141, A072146, A072147.
%K A072137 base,easy,nonn,nice
%O A072137 0,11
%A A072137 _Klaus Brockhaus_, Jun 24 2002