login
a(1) = 1; for n>1, let k = n-1 mod 4, then a(n) = operation k applied to the pair (a(n-1), n), where operation 1 is addition, operation 2 is difference (with reset to n if 0), operation 3 is multiplication and operation 0 is division with rounding.
2

%I #43 Mar 15 2021 08:27:24

%S 1,3,3,12,2,8,1,8,1,11,11,132,10,24,9,144,8,26,7,140,7,29,6,144,6,32,

%T 5,140,5,35,4,128,4,38,3,108,3,41,2,80,2,44,1,44,1,47,47,2256,46,96,

%U 45,2340,44,98,43,2408,42,100,41,2460,40,102,39,2496,38,104

%N a(1) = 1; for n>1, let k = n-1 mod 4, then a(n) = operation k applied to the pair (a(n-1), n), where operation 1 is addition, operation 2 is difference (with reset to n if 0), operation 3 is multiplication and operation 0 is division with rounding.

%C 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]

%C This occurs only when avoiding zeros and negative numbers form operations and also with four operation sequences [+, -, *, /]; [-, *, /, +]; [*, /, +, -] & [/, +, -, *] among total 24 permutation ones.

%H Alois P. Heinz, <a href="/A211346/b211346.txt">Table of n, a(n) for n = 1..5000</a>

%H Kival Ngaokrajang, <a href="/A211346/a211346.jpg">Scatter plot in log-log scale for n = 1..10^5</a>, Centipede-like pattern.

%F 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).

%e a(2) = a(1) + 2 = 3

%e a(3) = a(2) - 3 = 0, a(3) = n = 3

%e a(4) = a(3) * 4 = 12

%e a(5) = a(4) / 5 = round(12/5) = 2

%e a(6) = a(5) + 6 = 8,...

%p a:= proc(n) option remember; `if`(n<2, n,

%p [(x, y)->round(x/y), (x, y)->x+y,

%p (x, y)->`if`(x-y=0, y, abs(x-y)), (x, y)->x*y]

%p [1+irem(n-1, 4)](a(n-1), n))

%p end:

%p seq(a(n), n=1..100); # _Alois P. Heinz_, Feb 17 2013

%t 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]]]]];

%t Array[a, 100] (* _Jean-François Alcover_, Mar 15 2021 *)

%o (Small Basic)

%o a[1]=1

%o For n=2 To 100

%o nn = math.Remainder(n,4)

%o If nn = 2 Then ' operation +

%o a[n]=a[n-1]+n

%o Else

%o EndIf

%o If nn = 3 Then ' operation -

%o If a[n-1] = n Then

%o a[n]=n

%o Goto OUT

%o Else

%o EndIf

%o a[n]=Math.Abs(a[n-1]-n)

%o Else

%o EndIf

%o OUT:

%o If nn=0 Then ' operation *

%o a[n]=a[n-1]*n

%o Else

%o EndIf

%o If nn=1 Then ' operation /

%o a[n]=math.Round(a[n-1]/n)

%o Else

%o EndIf

%o EndFor

%o For j = 1 to 100

%o TextWindow.Write(j+" ")

%o TextWindow.Write(a[j])

%o TextWindow.WriteLine(" ")

%o EndFor

%K nonn,look

%O 1,2

%A _Kival Ngaokrajang_, Feb 05 2013