Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
