! ------------------ 3N+1 Problem. --------------------- ! We have an integer number N>1 and we apply the following procedure: ! If N is even we divide N with 2. If N is odd we multiply N with 3 and we add 1, ! so we have 3N+1. In the new number in each case (if it's not 1) we make again the ! same. Until now, for every number humans have tested the final number in which ! the procedure will terminate, is 1! This can't be proved until now. ! This program finds, how many times for a number N, we have to ! apply the procedure from which the 3N+1 problem is defined, ! to find number 1. ++++++Example for number 5: We have 5->16->8->4->2->1. ! So the procedure is being used 5 times. This program writes to a file (3N1_DATA) ! the number 5 and the number of times the above procedure occurs, plus 1, that means ! writes 5 6. And you choose the interval between two numbers. ! For example use A=1 , B=10000 and then import the file in Origin and make a plot. integer i,a,b,s,d 1 continue print *,'Choose A>0: (A is for the start-number)' read*,a if (a.lt.1) then goto 1 end if 2 continue print *,'Choose B>A: (B is the end-number)' read*,b if (b.lt.a) then goto 2 end if open(1,file='3N1_DATA',status='unknown') do i=a,b s=0 d=i 4 continue if (d.eq.1) then goto 3 end if s=s+1 if (mod(d,2).eq.0) then d=d/2 goto 4 else d=3*d+1 goto 4 end if 3 continue write(1,*) i , s+1 end do close=(1) end