My version for Day 02: calculate checksum of a data file containing lines of tab delimited integer numbers.
Checksum is the sum of the difference between the max and min value of each data row.
I used the "matrix" version of PARSE to load file into a matrix instead of an array of strings to be parsed later.
uses "console"
#MinVersion 1.10.4
'---Parse a Matrix from a file
string gMatrix()
parse(file "data.txt", gMatrix, $lf, $tab)
'---Calc and print CheckSum
printl CheckSum(gMatrix)
waitkey
function CheckSum(lMatrix() as String) as long
long row
long col
long lMin, lMax
long total
For row = 1 to UBound(lMatrix, 1)
lMin = +2147483647 '---Max possible long, see help "Numeric Variables"
lMax = -lMin '---Min possible long, see help "Numeric Variables"
For col = 1 to UBound(lMatrix, 2)
lMin = Min(lMin, lMatrix(row, col))
lMax = Max(lMax, lMatrix(row, col))
Next
total += lMax - lMin
Next
function = total
end function
Bookmarks