Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. tab= zeros(3,3);
  2. % 1-zielony 2-czerwony 3-zolty 4 niebieski
  3. wej=rand(1,20).*4;
  4. wej=wej+1;
  5. wej=floor(wej);
  6. r=1;
  7. for i=3:-1:2
  8. for j=1:3
  9. tab(j,i)=wej(r);
  10. r=r+1;
  11. end
  12. end
  13. wyj=zeros(1,20);
  14. %tab(3,3)=0;
  15. tab
  16. w=0;
  17. wo=1;
  18. for x=1:3
  19. % if x==1
  20. % wyj=tab(1,3);
  21. % tab(1,3)=tab(1,2);
  22. % tab(1,2)=0;
  23. % end
  24. for i=1:3
  25. for j=3:-1:1
  26. if tab(j,i)==0
  27. tab(j,i)=wej(r);
  28. r=r+1;
  29. w=1;
  30. break
  31. end
  32. end
  33. if w==1
  34. break
  35. end
  36. end
  37. if(x==1)
  38. wyj(wo)=tab(3,3);
  39. wo=wo+1;
  40. tab(3,3)=tab(3,2);
  41. tab(3,2)=tab(3,1);
  42. tab(3,1)=0;
  43. continue
  44. end
  45. for i=1:3
  46. if tab(i,3)==wyj(wo)
  47. ;wyj(wo)=tab(i,3)
  48. wo=wo+1;
  49. tab(i,3)=tab(i,2);
  50. tab(i,2)=tab(i,1);
  51. tab(i,1)=0;
  52. break
  53. else
  54. wyj(wo)=tab(3,3);
  55. wo=wo+1;
  56. tab(3,3)=tab(3,2);
  57. tab(3,2)=tab(3,1);
  58. tab(3,1)=0;
  59. break
  60. end
  61.  
  62. end
  63. end
  64. tab
  65. wyj
  66. wo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement