Create a roblox lua module containing a method that will create a matrix of a given size…
- User
Create a roblox lua module containing a method that will create a matrix of a given size consisting of false, and also with a method that will draw line of trues inside from x1 y1 to x2 y2, and a method to display this matrix where falses will be 0 and trues will be 1
Assistant
Here's a sample Roblox Lua module that meets your requirements:
local Matrix = {} Matrix.__index = Matrix function Matrix.new(width, height) local self = setmetatable({}, Matrix) self.width = width self.height = height self.matrix = {} for y = 1, height do self.matrix[y] = {} for x = 1, width do self.matrix[y][x] = false end end return self end function Matrix:drawLine(x1, y1, x2, y2) for y = y1, y2 do for x = x1, x2 do if x == x1 and y == y1 then self.matrix[y][x] = true else self.matrix[y][x] = false end end end end function Matrix:display() for y = 1, self.height do for x = 1, self.width do if self.matrix[y][x] then print("1", end = "") else print("0", end = "") end end print() end end return Matrix
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.