Package net.n1da.dev.euler.helper
Class Matrix
- java.lang.Object
-
- net.n1da.dev.euler.helper.Matrix
-
public class Matrix extends java.lang.Object
Objects of this class can store integer values in form of a two-dimensional matrix.- Since:
- 18.04.2015 15:37:20
- Author:
- Nico Danneberg
-
-
Method Summary
Modifier and Type Method Description long
findMaxProduct(boolean diagonals)
Checks every row / column to find the maximum product of all elements in a row / column.int
get(int col, int row)
Read the value ofdata
at the given coordinates.Matrix
getSection(int x, int y, int w)
Reads a square sub-matrix out of the current object.Matrix
getSection(int x, int y, int w, int h)
Reads a sub-matrix out of the current object.boolean
isSquare()
Checks, if this matrix is square.static Matrix
load(java.lang.String file, int w)
Loads thedata
of a new square matrix from a file.static Matrix
load(java.lang.String file, int w, int h)
Loads thedata
of a new square matrix from a file.boolean
set(int col, int row, int value)
Sets the value at the given coordinates.
-
-
-
Constructor Detail
-
Matrix
public Matrix(int w)
Creates a square matrix with the given width for both dimensions.- Parameters:
w
- thewidth
for both dimensions
-
-
Method Detail
-
get
public int get(int col, int row)
Read the value ofdata
at the given coordinates.- Parameters:
col
- the columnrow
- the row- Returns:
- the value at
data
[ column, row ]
-
getSection
public Matrix getSection(int x, int y, int w)
Reads a square sub-matrix out of the current object.- Parameters:
x
- starting columny
- starting roww
- thewidth
of the sub-matrix- Returns:
- the sub-matrix
-
getSection
public Matrix getSection(int x, int y, int w, int h)
Reads a sub-matrix out of the current object.
-
set
public boolean set(int col, int row, int value)
Sets the value at the given coordinates.- Parameters:
col
- the columnrow
- the rowvalue
- the new value- Returns:
- true, if the new value has stores successfully
-
findMaxProduct
public long findMaxProduct(boolean diagonals)
Checks every row / column to find the maximum product of all elements in a row / column. If wanted the diagonals are checked, too.
-
isSquare
public boolean isSquare()
Checks, if this matrix is square.- Returns:
- true, if matrix is square
-
load
public static Matrix load(java.lang.String file, int w)
Loads thedata
of a new square matrix from a file. Only the givenwidth
(andheight
) is read. Additional digits are ignored.- Parameters:
file
- the file to read fromw
- the dimensions of the new matrix- Returns:
- the new square matrix
-
load
public static Matrix load(java.lang.String file, int w, int h)
-
-