Cody

# Problem 44628. The other half of the Fibonacci sequence

Solution 1531197

Submitted on 17 May 2018
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
% Banning these to discourage hard-coded answers and silly 'scoring cheats'. Sorry if it disrupts some legitimate usage. % Please don't try any other hacks or workarounds. assessFunctionAbsence({'str2num','str2double','regexp', 'regexpi'}, 'FileName','negativeRabbits.m'); FR = fileread('negativeRabbits.m'); msg = 'Don''t hard-code your ''solution''.'; assert( ~any( cellfun( @(z) contains(FR, z) , {'54800875592', '716768017756', '9845401187926'} ) ) , msg )

2   Pass
% I don't think it's very good style to be using "ans". RE = regexp(fileread('negativeRabbits.m'), '\w+', 'match'); tabooWords = {'ans'}; testResult = cellfun( @(z) ismember(z, tabooWords), RE ); msg = ['Please do not include the following banned strings in your code!' char([10 13]) ... strjoin(RE(testResult)) char([10 13])]; assert(~any( cellfun( @(z) ismember(z, tabooWords), RE ) ), msg)

3   Fail
% This is important. assert( isequal( class(negativeRabbits(0)) , 'int64' ) , 'Wrong data type.')

F = 0

Wrong data type.

4   Fail
% Test Suite shall ensure it only ever checks n < 3. assert( isequal(negativeRabbits(+2), 1) , 'Failed at n =+2.' ) assert( isequal(negativeRabbits(+1), 1) , 'Failed at n =+1.' ) assert( isequal(negativeRabbits( 0), 0) , 'Failed at n = 0.' ) assert( isequal(negativeRabbits(-1), 1) , 'Failed at n =-1.' )

F = 2

Failed at n =+2.

5   Fail
for n = 0 : -1 : -10 assert( isequal(negativeRabbits(n)+negativeRabbits(n+1), negativeRabbits(n+2)) , ['Failed at n =' num2str(n) '.']) end;

F = 0 F = 1 F = 2

Failed at n =0.

6   Fail
for n = -10 : -1 : -20 assert( isequal(negativeRabbits(n)+negativeRabbits(n+1), negativeRabbits(n+2)) , ['Failed at n =' num2str(n) '.']) end;

Out of memory. The likely cause is an infinite recursion within the program. Error in negativeRabbits (line 13) F = negativeRabbits(n-2) + negativeRabbits(n-1)

7   Fail
for n = -20 : -1 : -40 assert( isequal(negativeRabbits(n)+negativeRabbits(n+1), negativeRabbits(n+2)) , ['Failed at n =' num2str(n) '.']) end;

Out of memory. The likely cause is an infinite recursion within the program. Error in negativeRabbits (line 13) F = negativeRabbits(n-2) + negativeRabbits(n-1)

8   Fail
for n = -40 : -1 : -77 assert( isequal(negativeRabbits(n)+negativeRabbits(n+1), negativeRabbits(n+2)) , ['Failed at n =' num2str(n) '.']) end;

Out of memory. The likely cause is an infinite recursion within the program. Error in negativeRabbits (line 13) F = negativeRabbits(n-2) + negativeRabbits(n-1)

9   Fail
% This is difficult, but feasible within the parameters of the problem. for n = -77 : -1 : -92 assert( isequal(negativeRabbits(n)+negativeRabbits(n+1), negativeRabbits(n+2)) , ['Failed at n =' num2str(n) '.']) end;

Out of memory. The likely cause is an infinite recursion within the program. Error in negativeRabbits (line 13) F = negativeRabbits(n-2) + negativeRabbits(n-1)