Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 9 : 5 4 exam _ 2 4 . 1 1 . 2 0 2 3 1 8 0 1 2 0 2 4
:
exam
Open the file
function readGridfilename
local fileioopengridtxt
if not file then
printFile not found"
return nil
end
Read the grid of numbers from a file
local grid
local dimensions file:readline
local rows, cols dimensions:match
rows, cols tonumberrows tonumbercols
for rows do
grid
for cols do
Iniciate the grid with a default value
grid
end
end
for line in file:lines do
local row, col, val line:match :
row,col,val tonumberrow tonumbercol
tonumberval
if row and col and val then
if gridrow and gridcol then
grid val Value in grid update
end
end
end
Close the file
file:close
return grid
end
Function to show values in a specific column of grid function showColumngrid col
if col or col #grid then
nrint Invalid column numher"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started