Problem 69. Find the peak 3n+1 sequence value
Solution Stats
Problem Comments
-
11 Comments
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
Solution Comments
Show commentsProblem Recent Solvers2498
Suggested Problems
-
396 Solvers
-
Getting the row and column location from a matrix
286 Solvers
-
Construct an index vector from two input vectors in vectorized fashion
389 Solvers
-
653 Solvers
-
964 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!