A Collatz sequence is the sequence where, for a given number n, the next number in the sequence is either n/2 if the number is even or 3n+1 if the number is odd. See Problem 21 for more information.
Let c(n) be the sequence for n, and p(n) be the peak value of that sequence. For a given threshold nmax, find the highest peak value max(p(n)) for all Collatz sequences starting with integers between 1 and nmax.
Nice one
Good problem!
function pmax = peakOfPeaks(nmax)
pmax=1;
tmp=[];
for i=1:nmax
j=i;
tmp=[tmp j];
while j~=1
if mod(j,2)==0
j=j/2;
tmp=[tmp j];
else
j=3*j+1;
tmp=[tmp j];
end
end
if pmax
How would I speed this up?
If I input nmax = 2^60, my program cannot finish.
This solution will fail for nmax = 2; so I had to swap the order of two lines. See Solution 1088355.
i'm totally lost with this!
wrong, corrected in soln 329062
I only feel justified in doing this because the previous best answer was a look-up table. :P
Clever pattern, but still gaming the system. This is not the absolute highest Collatz peak as you go to infinity. Yuval, you should be ashamed of submitting this without apologies.
This really doesn't solve the problem it's just gaming the results.
Boo.
Ooooooh this is evil.
Pathetic
11603 Solvers
Check to see if a Sudoku Puzzle is Solved
382 Solvers
1012 Solvers
353 Solvers
Find the dimensions of a matrix
327 Solvers