Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
user_solution = fileread('hungry_snake.m');
assert(isempty(strfind(user_solution,'regexp')));
assert(isempty(strfind(user_solution,'num2str')));
assert(isempty(strfind(user_solution,'interp')));
assert(isempty(strfind(user_solution,'fprintf')));
assert(isempty(strfind(user_solution,'assert')));
|
2 | Pass |
%%
fprintf('Testing...\n')
for a = 0:8,
% Get the matrix
M = hungry_snake(a);
%
% Check that all the numbers exist once in 2^a x 2^a matrix
assert(isequal(size(M),[2^a,2^a]),'Bad Size');
assert(isequal(1:numel(M),sort(M(:))'),'Not all numbers exist!');
%
% Find the locations of the numbers
[I,J] = arrayfun(@(x)find(M==x,1),1:numel(M));
%
% Check that the numbers form indeed a snake
assert(all((abs(diff(I))==1&diff(J)==0) | (abs(diff(J))==1&diff(I)==0)),'Not a Snake!');
%
% Check that there isn't a straight line longer than 4
msl = max(cellfun('length',regexp(sprintf('%d',[diff(I) NaN diff(J)]),'0+','match')));
if a>0, assert( msl < 4,'More than 4 consecutive numbers!'); end
fprintf('\ta=%d : OK!\n',a);
end
%
fprintf('\n.\nChuck Norris would be proud!\n')
%
%
Testing...
a=0 : OK!
a=1 : OK!
a=2 : OK!
a=3 : OK!
a=4 : OK!
a=5 : OK!
a=6 : OK!
a=7 : OK!
a=8 : OK!
.
Chuck Norris would be proud!
|
483 Solvers
173 Solvers
Test if a Number is a Palindrome without using any String Operations
181 Solvers
584 Solvers
Numbers spiral diagonals (Part 2)
63 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!