From 281adf9893c545e32d576fb7ac626b8b1b0eac18 Mon Sep 17 00:00:00 2001 From: Naej Date: Thu, 29 Dec 2016 15:25:02 +0100 Subject: [PATCH 1/2] =?UTF-8?q?fait=20les=20fx=20de=20merde=20demand=C3=A9?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LibMatrix/matrix.c | 119 +++++++++++++++++++++++++++++++++++++++++++-- LibMatrix/matrix.h | 18 +++++++ 2 files changed, 133 insertions(+), 4 deletions(-) diff --git a/LibMatrix/matrix.c b/LibMatrix/matrix.c index 873117f..cea56e1 100644 --- a/LibMatrix/matrix.c +++ b/LibMatrix/matrix.c @@ -621,10 +621,121 @@ bool * GetFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]){ } +Matrix applyRules (Matrix matrix,int Rules, int N){ + int RulesMatrix[9]; + int i = 0; + int power = 2; + int sum = 0; + int j = 0; + Matrix tempMatrix; + + if (Rules <= 0 || N < 1){ + return matrix; + } + + tempMatrix = CreateMatrix(); + + while(power<=512){ + + RulesMatrix[i] = Rules%power - sum; + sum = Rules%power; + + if (RulesMatrix[i]!=0){ + i++; + } + + power*=2; + } + + /* test code : print decomposition */ + /*for (j=0;jsize == 0 || matrix.rows->size == 0){ + return true; + } + return false; +} + +bool isMatrixSquare(Matrix matrix){ + if (matrix.colCount == matrix.rowCount){ + return true; + } + return false; +} + +bool isColumnEmpty(Matrix matrix,int nb){ + ListElement * Col = NULL; + + if (matrix.colCount < 1 || matrix.rowCount < 1){ + return true; + } + if (matrix.cols->size == 0 || matrix.rows->size == 0){ + return true; + } + + Col = GetElementPos(matrix.cols,nb); + if (Col == NULL || Col->data == NULL){ + return true; + } + + return false; +} + +bool isRowEmpty(Matrix matrix,int nb){ + ListElement * Row = NULL; + + if (matrix.colCount < 1 || matrix.rowCount < 1){ + return true; + } + if (matrix.cols->size == 0 || matrix.rows->size == 0){ + return true; + } + Row = GetElementPos(matrix.rows,nb); + if (Row == NULL || Row->data == NULL){ + return true; + } + + return false; +} + +bool equalsMatrix(Matrix m1, Matrix m2){ + int i = 0; + int j = 0; + + if (m1.colCount == m2.colCount && m1.rowCount == m2.rowCount){ + for (i=0;i Date: Thu, 29 Dec 2016 15:38:13 +0100 Subject: [PATCH 2/2] Fix du doublon d'apply rules --- LibMatrix/matrix.c | 45 +-------------------------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/LibMatrix/matrix.c b/LibMatrix/matrix.c index cea56e1..ec902a9 100644 --- a/LibMatrix/matrix.c +++ b/LibMatrix/matrix.c @@ -35,10 +35,7 @@ Matrix applyRules (Matrix matrix,int Rules, int N){ tempMatrix2 = matrixFromRules(tempMatrix1,i, RulesMatrix); freeMatrix(tempMatrix1); - tempMatrix1.colCount = tempMatrix2.colCount; - tempMatrix1.rowCount = tempMatrix2.rowCount; - tempMatrix1.cols = tempMatrix2.cols; - tempMatrix1.rows = tempMatrix2.rows; + tempMatrix1 = tempMatrix2; } return tempMatrix1; @@ -621,46 +618,6 @@ bool * GetFromRules(Matrix m, int ColPos, int RowPos, int n, int rules[]){ } -Matrix applyRules (Matrix matrix,int Rules, int N){ - int RulesMatrix[9]; - int i = 0; - int power = 2; - int sum = 0; - int j = 0; - Matrix tempMatrix; - - if (Rules <= 0 || N < 1){ - return matrix; - } - - tempMatrix = CreateMatrix(); - - while(power<=512){ - - RulesMatrix[i] = Rules%power - sum; - sum = Rules%power; - - if (RulesMatrix[i]!=0){ - i++; - } - - power*=2; - } - - /* test code : print decomposition */ - /*for (j=0;j