%I #20 Feb 11 2018 20:03:32
%S 4,2,6,3,7,7,22,4,19,2,10,8,5,23,19,5,8,20,16,3,9,11,17,9,39,6,12,24,
%T 14,20,78,6,36,9,15,21,27,17,34,4,81,10,39,12,55,18,76,10,31,40,10,7,
%U 7,13,46,25,32,15,28,21,21,79,37,7,37,37,23,10,43,16,74,22
%N Given n, define the sequence x(1) = n, thereafter if x(i) is even set x(i+1) = x(i)/2, if x(i) is odd and divisible by 3, 5 or 7 set x(i+1) = 5*x(i) + 1, otherwise set x(i+1) = 3*x(i) + 1. Then a(n) is the smallest i>1 such that x(i) = 1, 5, or 553, or -1 if none of those numbers is ever reached.
%C (The following comments needs editing - _N. J. A. Sloane_, Feb 11 2018)
%C This is the Syracuse sequence modified by adding a constraint.
%C if x is odd and divisible by 3 or 5 or 7 then x = 5*x + 1 instead of x = 3x + 1, and x = 3*x + 1 if not divisible by 3 or 5 or 7.
%C The sequence if x even then x = x/2 and if x odd then x = 5*x + 1 diverge for n even > 12 or n odd > 5.
%C More than 1/3 of the odd numbers are divisible by 3 or 5 or 7 so this sequence will diverge or if not the Syracuse sequence will converge, it is easy to find that with the constraint added this sequence converges but with different cycles which are function of the n starting point.
%C There are 3 different cycles to end this sequence with the repetition of the cycle.
%C The main one is with a cycle of 6 values 5, 26, 13, 40, 20, 10 for 3/4 of the n values.
%C The second one is the same as the Syracuse sequence 1,4,2 for 21/100 of the n values.
%C And a third with a cycle of 175 values starting 553, 2766, 1383, 6916 ... for 3.3/100 of the n values.
%e n = 1, x(1) = 1 , x(2)= 4, x(3) = 2, x(4) = 1 so a(1) = 4.
%t With[{a = {3, 5, 7}, b = {1, 5, 553}, nn = 10^3}, Array[Length@ NestWhileList[Function[n, Which[EvenQ@ n, n/2, And[OddQ@ n, AnyTrue[a, Divisible[n, #] &]], 5 n + 1, True, 3 n + 1]], #, FreeQ[b, #] &, {2, 1}, nn] /. k_ /; k == nn + 1 -> -1 &, 72]] (* _Michael De Vlieger_, Dec 31 2017 *)
%o (BASIC)
%o For n=1 to 5000
%o i=1:x=n
%o 10 i=i+1
%o If x-2*Int(x/2)=0 Then x=x/2:Goto 20
%o If x-3*Int(x/3)=0 or x-5*Int(x/5)=0 Then x=5*x+1:Goto 20
%o x=3*x+1
%o 20 if x=1 or x=5 or x=553 Then Print n;i:Goto 30
%o Goto 10
%o 30 Next n
%o End
%Y Cf. A006577, A297217.
%K nonn
%O 1,1
%A _Pierre CAMI_, Dec 28 2017
|