Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/matrix.py
diff options
context:
space:
mode:
Diffstat (limited to 'matrix.py')
-rwxr-xr-xmatrix.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/matrix.py b/matrix.py
new file mode 100755
index 0000000..2506229
--- /dev/null
+++ b/matrix.py
@@ -0,0 +1,85 @@
+from math import sqrt
+
+#Cell: represents a single cell of the matrix
+class Cell:
+ def __init__(self):
+ self.Color = 'white'
+
+ def GetColor(self):
+ return self.Color
+
+ def PaintCell(self, color):
+ self.Color = color
+
+#Matrix: represent the cell's matrix. Defines constructor
+class Matrix:
+ def __init__(self, rows, columns):
+ self.Rows = rows
+ self.Columns = columns
+ self.Values = []
+ for i in range(rows):
+ a=[0]*columns
+ self.Values.append(a)
+ for i in range(rows):
+ for j in range(columns):
+ self.Values[i][j] = Cell()
+
+#Cells: Number of matrix's cells.
+def CreateMatrix(Cells):
+
+ #Generate the number of rows and columns
+ #so matrix can be similar as possible to a square matrix
+
+ root = int(sqrt(Cells))
+ l = list(range(1,root+1))
+ l.reverse()
+ for i in l:
+ if((Cells%i)==0):
+ rows=i
+ break
+ columns = Cells / rows
+
+ #Got the matrix's dimension
+
+ matrix = Matrix(rows,columns)
+ return matrix;
+
+#Parameters: matrix, list of colors, and how many cells has to be painted in each color
+#Returns: True if the painting is correct, False if is not
+def CheckMatrix(matrix, colors, number_color):
+ painted = number_color
+
+ #Each color got no cells painted initially
+ for item in painted:
+ item = 0
+
+ rows = matriz.rows
+ columns = matriz.columns
+
+ #Walk over the matrix
+ for i in range(rows):
+ for j in range(columns):
+ #Walk over the list of colors
+ cont=0
+ for color in colors:
+ if matriz.Cells[i][j].GetColor() == color:
+ painted[cont]=painted[cont] + 1
+
+ cont=cont+1
+
+ #Check
+ #Controlar si la cantidad de celdas pintadas por color coinciden
+ #con las cantidades solicitadas
+ success=True
+ cont=0
+ for item in painted:
+ if painted[cont] != number_color[cont]:
+ success=False
+ break
+
+ cont=cont+1
+
+ return success
+
+#probar que funcione
+#CrearMatriz(24)