Cody

# Problem 44448. Project Euler: Problem 14 Longest Collatz sequence

Solution 1379114

Submitted on 13 Dec 2017 by James
• Size: 82
• This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('euler014.m'); assert(isempty(strfind(filetext, 'tic')),'tic forbidden'); assert(isempty(strfind(filetext, 'toc')),'toc forbidden'); assert(isempty(strfind(filetext, 'pause')),'pause forbidden');

2   Pass
N = 1234321; num_correct = 1117065; len_correct = 528; [num, len] = euler014(N); assert(isequal(num, num_correct)); assert(isequal(len, len_correct));

3   Pass
N = 10; num_correct = 9; len_correct = 20; [num, len] = euler014(N); assert(isequal(num, num_correct)); assert(isequal(len, len_correct));

4   Pass
N = 100; num_correct = 97; len_correct = 119; [num, len] = euler014(N); assert(isequal(num, num_correct)); assert(isequal(len, len_correct));

5   Pass
N = 1000; num_correct = 871; len_correct = 179; [num, len] = euler014(N); assert(isequal(num, num_correct)); assert(isequal(len, len_correct));

6   Pass
N = 1e4; num_correct = 6171; len_correct = 262; [num, len] = euler014(N); assert(isequal(num, num_correct)); assert(isequal(len, len_correct));

7   Pass
N = 1e5; num_correct = 77031; len_correct = 351; [num, len] = euler014(N); assert(isequal(num, num_correct)); assert(isequal(len, len_correct));

8   Pass
N = 1e6; num_correct = 837799; len_correct = 525; [num, len] = euler014(N); assert(isequal(num, num_correct)); assert(isequal(len, len_correct));

9   Pass
N = 1e7; num_correct = 8400511; len_correct = 686; tic; [num, len] = euler014(N); t = toc; t assert(isequal(num, num_correct)); assert(isequal(len, len_correct)); assert(t < 1.5); assert(t > 0.001);

t = 0.5593

10   Pass
N = 1e8; num_correct = 63728127; len_correct = 950; tic; [num, len] = euler014(N); t = toc; t assert(isequal(num, num_correct)); assert(isequal(len, len_correct)); assert(t < 15); assert(t > 1);

t = 6.6206

11   Pass
N = randi([7e7, 1e8]); num_correct = 63728127; len_correct = 950; tic; [num, len] = euler014(N); t = toc; t assert(isequal(num, num_correct)); assert(isequal(len, len_correct)); assert(t < 15); assert(t > 1);

t = 7.1259