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.
Solution Stats
Problem Comments
11 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers2564
Suggested Problems
-
4180 Solvers
-
2176 Solvers
-
Check to see if a Sudoku Puzzle is Solved
337 Solvers
-
Determine if a Given Number is a Triangle Number
396 Solvers
-
Side of an equilateral triangle
6866 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Nice one
Good problem!
good.
If you want to add more tests: https://oeis.org/A006884 and https://oeis.org/A006885 contain the relevant sequences.
Why the leading solution size is 0 ? Is it for everyone or just me
@Tanzil Parvez (Emon): the hack solutions (hopefully all) have been deleted from this problem.
Wrong test cases! I checked on internet and found all the test cases except case 1 are wrong.
The test cases are all correct. You have simply not understood what the question is asking.
Broken link in description.
Link has been updated.
why does it not work it can run successfully in matalb
function pmax = peakOfPeaks(nmax)
B=[]
for n=1:1:nmax
A=[];
if n==1
A=1
else A=n
end
while n~=1
if mod(n,2)==1
A=[A,3*n+1];
n=3*n+1
else A=[A,n/2];
n=n/2
end
end
B=[B,max(A)]
end
pmax=max(B)
end