This solution is outdated. To rescore this solution, sign in.
The border of zeros is unnecessary. In fact, it is a flaw in the test suite that it regards a case as being "multi-survivor" when one of those survivors is in the border.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
[mcell] = Life;
[nr,nc]=size(mcell);
% check for uniqueness
valid=1;
tic
for k=1:nc-1
mk=mcell{k};
for p=k+1:nc
mp=mcell{p};
mkp=mk==mp;
if all(mkp(:))
valid=0;
end
end
end
assert(valid==1,sprintf('Not all unique solutions'));
toc
% run an evolution and verify
tic
for k=1:nc
m=mcell{k};
m=[zeros(1,6);zeros(4,1) m zeros(4,1);zeros(1,6)];
mc=conv2(m,[1 1 1;1 0 1;1 1 1],'same');
m=~(mc<2 | mc>3) & ((m & mc==2) | (m & mc==3) | (~m & mc==3));
assert(isequal(nnz(m),1),sprintf('Non-Single survivor solution'))
end
toc
assignin('caller','score',min(200,max(0,600-nc)));
Elapsed time is 0.068820 seconds.
Elapsed time is 0.037857 seconds.
|
Find the two most distant points
1628 Solvers
284 Solvers
1882 Solvers
Find matching string from a list of strings
77 Solvers
Is this triangle right-angled?
2394 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!