OFFSET
1,3
COMMENTS
p^a(n) = A084110(p^(n-1)) for n>1 and p prime. - Reinhard Zumkeller, May 12 2003
Absolute first differences of A085059; abs(a(n+1)-a(n)) = n, see also A086283. - Reinhard Zumkeller, Oct 17 2014
For n>3, when a(n) = 3, a(n+1) is in A116970. - Bill McEachen, Oct 03 2023
LINKS
N. J. A. Sloane, Table of n, a(n) for n = 1..29524 (Up to the 10th 0 term)
FORMULA
This is a concatenation S_0, S_1, S_2, ... where S_i = [b_0, b_1, ..., b_{3^(i+1)-1}] with b_0 = 0, b_{2j-1} = k+1-j, b_{2j} = 2k+j (j=1..k), k=(3^(i+1)-1)/2. E.g. S_0 = [0, 1, 3], S_1 = [0, 4, 9, 3, 10, 2, 11, 1, 12].
a((3^n-1)/2) = 0; a((3^n-1)/2 + 2k-1) = (3^n+1)/2 - k for 1 <= k <= (3^n-1)/2; a((3^n-1)/2 + 2k) = 3^n - 1 + k for 1 <= k < (3^n-1)/2. - Benoit Cloitre, Jan 09 2003 [Corrected by Jianing Song, May 25 2021]
a(n) = (n-1+a(n-1)) mod (2*(n-1)). - Jon Maiga, Jul 09 2021
MAPLE
MATHEMATICA
a[1]=0; a[n_] := a[n]=If[a[n-1]>=n-1, a[n-1]-n+1, a[n-1]+n-1]
Transpose[ NestList[ If[First[#]>=Last[#], {First[#]-Last[#], Last[#]+1}, {First[#]+Last[#], Last[#]+1}]&, {0, 1}, 80]][[1]] (* Harvey P. Dale, Jun 20 2011 *)
s = 0; Table[If[s < n, s = s + n, s = s - n], {n, 0, 80}] (* Horst H. Manninger, Dec 03 2018 *)
PROG
(Haskell)
a008344 n = a008344_list !! (n-1)
a008344_list = 0 : f 0 [1..] where
f x (z:zs) = y : f y zs where y = if x < z then x + z else x - z
-- Reinhard Zumkeller, Oct 17 2014, May 08 2012
(PARI) a(n) = my(expo = logint(2*n+1, 3), res = n - (3^expo-1)/2); if(res==0, 0, if(res%2, (3^expo-res)/2, 3^expo-1+res/2)) \\ Jianing Song, May 25 2021
CROSSREFS
KEYWORD
AUTHOR
EXTENSIONS
Name edited by Dmitry Kamenetsky, Feb 14 2017
STATUS
approved