blob: 250622944e5ce224e9ec6bffa26cdc5aef44db46 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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)
|