Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x = importdata('input.txt');
- folds = {'x',655;'y',447;'x',327;'y',223;'x',163;'y',111;'x',81;'y',55;'x',40;'y',27;'y',13;'y',6}; % manually extracted
- M = false(max(x(:,2))+1,max(x(:,1))+1);
- M(sub2ind(size(M),x(:,2)+1,x(:,1)+1)) = true;
- for k=1:size(folds,1)
- M = foldM(M,folds{k,1}=='x',folds{k,2});
- end
- disp(char(M*35))
- function M = foldM(M,direction,val)
- if direction==0
- M1 = M(1:val,:);
- M2 = flipud(M(val+2:end,:));
- if size(M1,1)>size(M2,1)
- M2 = [false(size(M1,1)-size(M2,1),size(M2,2));M2];
- else
- M1 = [false(size(M2,1)-size(M1,1),size(M1,2));M1];
- end
- else
- M1 = M(:,1:val);
- M2 = fliplr(M(:,val+2:end));
- if size(M1,2)>size(M2,2)
- M2 = [false(size(M2,1),size(M1,2)-size(M2,2)),M2];
- else
- M1 = [false(size(M2,1),size(M2,2)-size(M1,2)),M1];
- end
- end
- M = M1|M2;
- end
Advertisement
Add Comment
Please, Sign In to add comment