A072137 Length of the preperiodic part of the 'Reverse and Subtract' trajectory of n.
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
Examples
a(15) = 4 since 15 -> |15- 51| = 36 -> |36 - 63| = 27 -> |27 - 72| = 45 -> |45 - 54| = 9.
Links
- R. Zumkeller, Table of n, a(n) for n = 0..10000
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 *)
Comments