Cody

# Problem 2026. Skyscrapers - Puzzle

Solution 2668976

Submitted on 8 Jul 2020
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   Fail
%Games Feb 2014 #1 vr=[0 0 1 0 5]'; %1 vL=[0 4 4 0 0]'; vd=[2 2 0 1 3]; vu=[3 0 0 2 0]; tic m=solve_skyscrapers(vr,vL,vd,vu) toc nr=length(vr); nrsum=nr*(nr+1)/2; assert(nr*nrsum==sum(m(:))) assert(nr==size(m,1)); assert(nr==size(m,2)); assert(all(sum(m)==nrsum)); assert(all(sum(m,2)==nrsum)); mt=m; % view right check vz=vr; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k vz=vd; % view down check for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k mt=fliplr(m); % view Left check vz=vL; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)); % Assert check of valid count end % if end % k mt=flipud(m); % view Up check vz=vu; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k

m = [] Elapsed time is 0.003891 seconds.

Assertion failed.

2   Fail
%Games Feb 2014 #2 vr=[0 4 0 2 0]'; %2 vL=[5 1 0 0 0]'; vd=[0 0 3 0 0]; vu=[4 1 2 0 2]; tic m=solve_skyscrapers(vr,vL,vd,vu) toc nr=length(vr); nrsum=nr*(nr+1)/2; assert(nr*nrsum==sum(m(:))) assert(nr==size(m,1)); assert(nr==size(m,2)); assert(all(sum(m)==nrsum)); assert(all(sum(m,2)==nrsum)); mt=m; % view right check vz=vr; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k vz=vd; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k mt=fliplr(m); % view right check vz=vL; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)); % Assert check of valid count end % if end % k mt=flipud(m); vz=vu; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k

m = [] Elapsed time is 0.000207 seconds.

Assertion failed.

3   Fail
%Games Feb 2014 #3 vr=[5 2 2 0 0]'; %3 vL=[0 3 0 3 4]'; vd=[5 0 0 0 0]; vu=[0 2 0 0 0]; tic m=solve_skyscrapers(vr,vL,vd,vu) toc nr=length(vr); nrsum=nr*(nr+1)/2; assert(nr*nrsum==sum(m(:))) assert(nr==size(m,1)); assert(nr==size(m,2)); assert(all(sum(m)==nrsum)); assert(all(sum(m,2)==nrsum)); mt=m; % view right check vz=vr; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k vz=vd; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k mt=fliplr(m); % view right check vz=vL; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)); % Assert check of valid count end % if end % k mt=flipud(m); vz=vu; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k

m = [] Elapsed time is 0.000199 seconds.

Assertion failed.

4   Fail
%Games Feb 2014 #4 vr=[0 0 4 5 0]'; %4 vL=[0 0 0 0 0]'; vd=[2 0 2 3 0]; vu=[0 0 0 0 0]; tic m=solve_skyscrapers(vr,vL,vd,vu) toc nr=length(vr); nrsum=nr*(nr+1)/2; assert(nr*nrsum==sum(m(:))) assert(nr==size(m,1)); assert(nr==size(m,2)); assert(all(sum(m)==nrsum)); assert(all(sum(m,2)==nrsum)); mt=m; % view right check vz=vr; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k vz=vd; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k mt=fliplr(m); % view right check vz=vL; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)); % Assert check of valid count end % if end % k mt=flipud(m); vz=vu; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k

m = [] Elapsed time is 0.000195 seconds.

Assertion failed.

5   Fail
%Games Feb 2014 #5 vr=[3 5 0 0 0]'; %5 vL=[0 0 4 0 0]'; vd=[0 0 0 0 0]; vu=[2 0 1 0 2]; tic m=solve_skyscrapers(vr,vL,vd,vu) toc nr=length(vr); nrsum=nr*(nr+1)/2; assert(nr*nrsum==sum(m(:))) assert(nr==size(m,1)); assert(nr==size(m,2)); assert(all(sum(m)==nrsum)); assert(all(sum(m,2)==nrsum)); mt=m; % view right check vz=vr; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k vz=vd; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k mt=fliplr(m); % view right check vz=vL; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)); % Assert check of valid count end % if end % k mt=flipud(m); vz=vu; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k

m = [] Elapsed time is 0.000645 seconds.

Assertion failed.

6   Fail
vr=[0 0 3 0 0]'; %Games Feb 2014 #6 vL=[3 0 0 1 0]'; vd=[0 0 0 0 0]; vu=[5 2 0 0 0]; tic m=solve_skyscrapers(vr,vL,vd,vu) toc nr=length(vr); nrsum=nr*(nr+1)/2; assert(nr*nrsum==sum(m(:))) assert(nr==size(m,1)); assert(nr==size(m,2)); assert(all(sum(m)==nrsum)); assert(all(sum(m,2)==nrsum)); mt=m; % view right check vz=vr; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k vz=vd; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k mt=fliplr(m); % view right check vz=vL; for k=1:nr if vz(k)>0 c=1; shi=mt(k,1); for z=2:nr if mt(k,z)>shi shi=mt(k,z); c=c+1; end end % z c; vz(k); assert(c==vz(k)); % Assert check of valid count end % if end % k mt=flipud(m); vz=vu; for k=1:nr if vz(k)>0 c=1; shi=mt(1,k); for z=2:nr if mt(z,k)>shi shi=mt(z,k); c=c+1; end end % z c; vz(k); assert(c==vz(k)) % Assert check of valid count end % if end % k

m = [] Elapsed time is 0.000196 seconds.

Assertion failed.