OFFSET
1,2
COMMENTS
After n=1, the values of n where a(n)=1 occur in pairs: 7, 9; 43, 45; 207, 209; 943, 945; 4255, 4257; 19159, 19161; 86227,86229; 388035, 388037; 1746171, 1746173; 7857783, 7857785; 35360035, 35360037; etc. [edited by Jon E. Schoenfield, Dec 11 2014]
This occurs only when avoiding zeros and negative numbers form operations and also with four operation sequences [+, -, *, /]; [-, *, /, +]; [*, /, +, -] & [/, +, -, *] among total 24 permutation ones.
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..5000
Kival Ngaokrajang, Scatter plot in log-log scale for n = 1..10^5, Centipede-like pattern.
FORMULA
a(1) = 1, for n >= 2; if (n - (4 * (round(n/4) - 1)) = 2, a(n) = a(n - 1) + n; if (n - (4 * (round(n/4) - 1)) = 3, a(n) = abs(a(n - 1) - n), if a(n - 1) = n, a(n) = n; if (n - (4 * (round(n/4) - 1)) = 4, a(n) = a(n-1) * n; if (n - (4 * (round(n/4) - 1)) = 5, a(n) = round(a(n - 1) / n).
EXAMPLE
a(2) = a(1) + 2 = 3
a(3) = a(2) - 3 = 0, a(3) = n = 3
a(4) = a(3) * 4 = 12
a(5) = a(4) / 5 = round(12/5) = 2
a(6) = a(5) + 6 = 8,...
MAPLE
a:= proc(n) option remember; `if`(n<2, n,
[(x, y)->round(x/y), (x, y)->x+y,
(x, y)->`if`(x-y=0, y, abs(x-y)), (x, y)->x*y]
[1+irem(n-1, 4)](a(n-1), n))
end:
seq(a(n), n=1..100); # Alois P. Heinz, Feb 17 2013
MATHEMATICA
a[n_] := a[n] = If[n==1, 1, With[{k = Mod[n, 4]}, Switch[k, 0, a[n-1] n, 1, Round[a[n-1]/n], 2, a[n-1]+n, 3, If[a[n-1]==n, n, Abs[a[n-1]-n]]]]];
Array[a, 100] (* Jean-François Alcover, Mar 15 2021 *)
PROG
(Small Basic)
a[1]=1
For n=2 To 100
nn = math.Remainder(n, 4)
If nn = 2 Then ' operation +
a[n]=a[n-1]+n
Else
EndIf
If nn = 3 Then ' operation -
If a[n-1] = n Then
a[n]=n
Goto OUT
Else
EndIf
a[n]=Math.Abs(a[n-1]-n)
Else
EndIf
OUT:
If nn=0 Then ' operation *
a[n]=a[n-1]*n
Else
EndIf
If nn=1 Then ' operation /
a[n]=math.Round(a[n-1]/n)
Else
EndIf
EndFor
For j = 1 to 100
TextWindow.Write(j+" ")
TextWindow.Write(a[j])
TextWindow.WriteLine(" ")
EndFor
CROSSREFS
KEYWORD
nonn,look
AUTHOR
Kival Ngaokrajang, Feb 05 2013
STATUS
approved