matrixUtil
An utility module for working with matrixes. A matrix is simply an array consisting of arrays, for e.g:
local matrix = {
{1, 1, 2},
{1, 1, 1},
{3, 3, 3},
}
Functions
matchingRowsValue
matrixUtil.
matchingRowsValue
(
matrix:
{
{
T
}
}
,
depth:
number?
) →
T?
Searches matrix
row-wise, and returns a value in a row that matches with
the rest of the values of that row. E.g:
local matrix = {
{1, 1, 1},
{5, 5, 2},
{0, 0, 2},
}
print(matrixUtil.matchingRowsValue(matrix)) --> 1 (The first row is equally matched (all 1s))
Additionally, you can specify depth
if you want to control how far the
method should check each row. For e.g:
local matrix = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{1, 1, 1, 0},
}
print(matrixUtil.matchingRowsValue(matrix, 3)) --> 1 (The last row's first 3 values (1s) are equally matched)
print(matrixUtil.matchingRowsValue(matrix, 4)) --> nil (No row's first 4 values are equally matched)
matchingDiagonalColumnsValue
matrixUtil.
matchingDiagonalColumnsValue
(
matrix:
{
{
T
}
}
,
depth:
number?
) →
T?
Searches matrix
diagonally, and returns a value that matches with the
rest of the values of the arrays in matrix
.
E.g:
local matrix = {
{5, 0, 0},
{0, 5, 0},
{0, 0, 5},
}
print(matrixUtil.matchingDiagonalColumnsValue(matrix)) --> 1 (A column has matching values diagonally (just 5s))
Additionally, you can specify depth
if you want to control how far the
method should search matrix
diagonally. For e.g:
local matrix = {
{2, 0, 0, 0},
{0, 2, 0, 0},
{0, 0, 2, 0},
{0, 0, 0, 0},
}
print(matrix.matchingDiagonalColumnsValue(matrix, 3)) --> 2 (A column has FIRST 3 matching values diagonally (just 2s))
matchingColumnsValue
matrixUtil.
matchingColumnsValue
(
matrix:
{
{
T
}
}
,
depth:
number?
) →
T?
Searches matrix
column-wise and returns a value of a column that matches
with the rest of the values of that column. E.g:
local matrix = {
{5, 0, 0},
{5, 1, 0},
{5, 0, 1},
}
print(matrixUtil.matchingColumnsValue(matrix)) --> 5 (A column has ALL equally matching values (just 5s))
Additionally, you can specify depth
if you want to control how far the
method should check each column. For e.g:
local matrix = {
{5, 0, 0},
{5, 0, 0},
{2, 1, 1},
}
print(matrixUtil.matchingColumnsValue(matrix, 2)) --> 5 (A column has FIRST 2 matching values (just 5s))