Advertisement
AlexMastang

Untitled

Sep 21st, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. local i
  2. local x
  3. local y
  4. local amount
  5. local n 40
  6. local b = n/2
  7. local r = 100
  8. local v = {}
  9. local m = {}
  10.  
  11.  
  12. -- Stampa del bordo X
  13. function StampaBordoX()
  14. i = 0;
  15. write("+")
  16. while i < b do
  17. write("----+")
  18. i = i + 1
  19. end
  20. print()
  21. end
  22.  
  23. -- Equivalente del printf in lua
  24. function comma_value(amount)
  25. local formatted, k = amount, 0
  26. while true do
  27. formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  28. if (not k) or k==0 then
  29. break
  30. end
  31. end
  32. return formatted
  33. end
  34.  
  35. i = 0
  36. for i=1,b do
  37. v[i] = math.random(1,r)
  38. end
  39.  
  40. -- Assegnamento della matrice
  41. x = 0
  42. StampaBordoX()
  43. while x < b do
  44. y = 0
  45. write("|")
  46. while y < b do
  47. m[x][y] = v[math.random(1,n)]
  48. comma_value(m[x][y])
  49. y = y + 1
  50. end
  51. print()
  52. StampaBordoX()
  53. x = x + 1
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement