Cody

# Problem 46691. Kaggle: Planetoid Game of Life - Solve 40 non-trivial Puzzles

Solution 3180506

Submitted on 12 Oct 2020 by Tim
• Size: 186
• 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
%'https://sites.google.com/site/razapor/matlab_cody/mtest.mat?attredirects=0&d=1'; %mtest format is [casenumer, iterations, start1:625,finish1:625] for 50K cases 0:49999 %'https://sites.google.com/site/razapor/matlab_cody/mtrain.mat?attredirects=0&d=1'; tic fname='https://sites.google.com/site/razapor/matlab_cody/mtest.mat?attredirects=0&d=1'; urlwrite(fname,'mtest.mat') %1.22s load('mtest.mat'); %0.42s toc numtosolve=40; mstart = solveLife(mtest,numtosolve); toc mstart=unique(mstart,'rows'); % remove exact duplicate solutions %Check for Trivial solutions; Life(mtest(case))==mtest(case) valid=1; for i=1:size(mstart,1) % icase=mstart(i,1); %50000:99999 iter=mtest(icase-49999,2); %Test cases start at 50000 A=reshape(mtest(icase-49999,3:end),25,25); Abase=A; for j=1:iter C=0; for r=-1:1 % -1 Up Using circshift to perform wrap convolution Ar=circshift(A,r,1); for c=-1:1 % -1 Left Arc=circshift(Ar,c,2); C=C+Arc; end end A = C==3 | A&C==4; end %j if isequal(Abase,A) % mtest [case, iter, data1:625] valid=0; %Trivial solution entered break; end end %main loop i toc % Trivial check timer Lprocess=size(mstart,1)*valid; valid=0; % Reset valid as counter for solutions for i=1:Lprocess % skip if any were trivial icase=mstart(i,1); %50000:99999 iter=mtest(icase-49999,2); %Test cases start at 50000 A=reshape(mstart(i,2:end),25,25); for j=1:iter C=0; for r=-1:1 % -1 Up Using circshift to perform wrap convolution Ar=circshift(A,r,1); for c=-1:1 % -1 Left Arc=circshift(Ar,c,2); C=C+Arc; end end A = C==3 | A&C==4; end %j if ~isequal(A(:)',mtest(icase-49999,3:end)) % mtest [case, iter, data1:625] valid=0; %Evolved does not match goal break; else valid=valid+1; end end %main loop i toc assert(valid>=40)

ans = '/users/mss.system.Mscjl9/mtest.mat' Elapsed time is 1.921027 seconds. Elapsed time is 16.974751 seconds. Elapsed time is 16.995950 seconds. Elapsed time is 17.007554 seconds.