Cody

Problem 788. Tiles Contest: Perfect Solutions for Large Unique Tile Boards

Solution 3123106

Submitted on 8 Oct 2020 by Richard Zapor
  • Size: 278
  • 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
feval(@assignin,'caller','score',2000);

2   Pass
format short format compact global net_time %fn='http://tinyurl.com/zapor-Tiles-sample-mat'; %fn='http://tinyurl.com/matlab-tiles-mat'; %testsuite_sample.mat fn='https://sites.google.com/site/razapor/matlab_cody/testsuite_Tiles_sample.mat?attredirects=0&d=1'; testSuiteFile = 'raz_tiles.mat'; urlwrite(fn,testSuiteFile); brd=59; tests = load(testSuiteFile,'testsuite'); tiles = tests.testsuite(brd).tiles; rows = tests.testsuite(brd).r; cols = tests.testsuite(brd).c; boardSize = [rows, cols]; [board,orientation]=board_perfect(boardSize,tiles); % run twice for timing t0=clock; [board,orientation]=board_perfect(boardSize,tiles); dt=etime(clock,t0)*1e3; % verify score t=tiles; ntiles=size(tiles,1); te = [t; t(:,[2:4,1]); t(:,[3:4,1:2]); t(:,[4,1:3])]; % build check arrays UD, LR LR=zeros(rows,2*cols); UD=zeros(2*rows,cols); for r=1:rows for c=1:cols tptr=board(r,c); tor=orientation(tptr); UD(2*r-1,c)=te(tptr+ntiles*(tor-1),1); UD(2*r,c)=te(tptr+ntiles*(tor-1),3); LR(r,2*c-1)=te(tptr+ntiles*(tor-1),4); LR(r,2*c)=te(tptr+ntiles*(tor-1),2); end end checksum=sum([LR(:,1)' LR(:,end)' UD(1,:) UD(end,:)]); for idx=2:2:2*rows-2 % LR Square array assumed here checksum=checksum+sum(LR(:,idx)-LR(:,idx+1))+sum(UD(idx,:)-UD(idx+1,:)); end assert(checksum==0,sprintf('Checksum = %s\n',num2str(checksum))); net_time=dt

net_time = 71.1510

3   Pass
global net_time temp=net_time; % anti-cheat %fn='http://tinyurl.com/zapor-Tiles-contest-mat'; %fn='http://tinyurl.com/matlab-tilesC-mat'; %testsuite_actual.mat fn='https://sites.google.com/site/razapor/matlab_cody/testsuite_Tiles_contest.mat?attredirects=0&d=1'; testSuiteFile = 'raz_tiles.mat'; urlwrite(fn,testSuiteFile); brd=6; tests = load(testSuiteFile,'testsuite'); tiles = tests.testsuite(brd).tiles; rows = tests.testsuite(brd).r; cols = tests.testsuite(brd).c; boardSize = [rows, cols]; [board,orientation]=board_perfect(boardSize,tiles); % run twice for timing t0=clock; [board,orientation]=board_perfect(boardSize,tiles); dt=etime(clock,t0)*1e3 % verify score t=tiles; ntiles=size(tiles,1); te = [t; t(:,[2:4,1]); t(:,[3:4,1:2]); t(:,[4,1:3])]; % build check arrays UD, LR LR=zeros(rows,2*cols); UD=zeros(2*rows,cols); for r=1:rows for c=1:cols tptr=board(r,c); tor=orientation(tptr); UD(2*r-1,c)=te(tptr+ntiles*(tor-1),1); UD(2*r,c)=te(tptr+ntiles*(tor-1),3); LR(r,2*c-1)=te(tptr+ntiles*(tor-1),4); LR(r,2*c)=te(tptr+ntiles*(tor-1),2); end end checksum=sum([LR(:,1)' LR(:,end)' UD(1,:) UD(end,:)]); for idx=2:2:2*rows-2 % LR Square array assumed here checksum=checksum+sum(LR(:,idx)-LR(:,idx+1))+sum(UD(idx,:)-UD(idx+1,:)); end assert(checksum==0,sprintf('Checksum = %s\n',num2str(checksum))); net_time=(dt+temp)/2

dt = 34.9300 net_time = 53.0405

4   Pass
global net_time % Limit Score to 2000 for graph quality t=mtree('board_perfect.m','-file'); scr=floor(length(t.nodesize)/10+net_time); scr=min(scr,2000) feval(@assignin,'caller','score',floor(scr)); %fh=fopen('board_perfect.m','wt'); %fprintf(fh,'%s\n',repmat('1;',[1,round(scr/2)])); %fclose(fh);

scr = 80

Suggested Problems

More from this Author246

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!