Guest User

Dag 13 in MATLAB

a guest
Dec 13th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.86 KB | None | 0 0
  1. x       = importdata('input.txt');
  2. 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
  3. M       = false(max(x(:,2))+1,max(x(:,1))+1);
  4. M(sub2ind(size(M),x(:,2)+1,x(:,1)+1)) = true;
  5.  
  6. for k=1:size(folds,1)
  7.     M = foldM(M,folds{k,1}=='x',folds{k,2});
  8. end
  9. disp(char(M*35))
  10.  
  11. function M = foldM(M,direction,val)
  12. if direction==0
  13.     M1 = M(1:val,:);
  14.     M2 = flipud(M(val+2:end,:));
  15.     if size(M1,1)>size(M2,1)
  16.         M2 = [false(size(M1,1)-size(M2,1),size(M2,2));M2];
  17.     else
  18.         M1 = [false(size(M2,1)-size(M1,1),size(M1,2));M1];
  19.     end
  20. else
  21.     M1 = M(:,1:val);
  22.     M2 = fliplr(M(:,val+2:end));
  23.     if size(M1,2)>size(M2,2)
  24.         M2 = [false(size(M2,1),size(M1,2)-size(M2,2)),M2];
  25.     else
  26.         M1 = [false(size(M2,1),size(M2,2)-size(M1,2)),M1];
  27.     end
  28. end
  29. M = M1|M2;
  30. end
Advertisement
Add Comment
Please, Sign In to add comment