Skip to content

Instantly share code, notes, and snippets.

@ajaylakhimale
Created March 16, 2022 08:15
Show Gist options
  • Save ajaylakhimale/d252685f90631518b50afa4cbac89f10 to your computer and use it in GitHub Desktop.
Save ajaylakhimale/d252685f90631518b50afa4cbac89f10 to your computer and use it in GitHub Desktop.
it's fun coding matrix.
// As Dart does not have multidimensional arrays or lists to be specific.
// I'm trying to create a matrix of 3x3.
class MatrixT{
// matrix has 9 elements as follows
// R11, R12, R13
// R21, R22, R23
// R31, R32, R33
// to create a matrix we're gonna create a list of length 9
// each 3 elements represent each row. 1 2 3 respectively.
int r11 = 0;
int r12 = 0;
int r13 = 0;
int r21 = 0;
int r22 = 0;
int r23 = 0;
int r31 = 0;
int r32 = 0;
int r33 = 0;
MatrixT(this.r11,
this.r12,
this.r13,
this.r21,
this.r22,
this.r23,
this.r31,
this.r32,
this.r33,);
List createMatrix(){
List<int> matrix = [];
matrix.add(r11);
matrix.add(r12);
matrix.add(r13);
matrix.add(r21);
matrix.add(r22);
matrix.add(r23);
matrix.add(r31);
matrix.add(r32);
matrix.add(r33);
return matrix;
}
// Todo: create a method which return leftDiagonal addition and rightDiagonal addition.
void printLeftDiagonal(){
}
// you can modify this code and make it look like exactly same as 3x3 Matrix.
// by creating 3 lists and adding elements in their respective place and then
// create a method to print all the 3 lists one by one so it looks like a matrix
}
void main (){
MatrixT newMatrix = MatrixT(1,2,2,3,4,5,6,7,8);
var myMat = newMatrix.createMatrix();
print(myMat);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment