Skip to content

Commit d38b935

Browse files
committed
Fix ruff errors
1 parent 92449bf commit d38b935

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Diff for: backtracking/coloring.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ def valid_coloring(
2121
If all neighbours validate the constraint return True
2222
2323
Parameters:
24-
neighbours (list[int]): The list representing which vertices are adjacent to the current vertex.
25-
1 indicates an edge between the current vertex and the neighbour.
26-
colored_vertices (list[int]): List of current color assignments for all vertices (-1 means uncolored).
24+
neighbours (list[int]): The list representing which vertices
25+
are adjacent to the current vertex.
26+
1 indicates an edge between the current vertex
27+
and the neighbour.
28+
colored_vertices (list[int]): List of current color assignments for all vertices
29+
(-1 means uncolored).
2730
color (int): The color we are trying to assign to the current vertex.
2831
2932
Returns:
30-
bool: True if the vertex can be safely colored with the given color, otherwise False.
33+
bool: True if the vertex can be safely colored with the given color,
34+
otherwise False.
3135
3236
Examples:
3337
>>> neighbours = [0, 1, 0, 1, 0]
@@ -73,10 +77,12 @@ def util_color(
7377
7478
Parameters:
7579
graph (list of list of int): Adjacency matrix representing the graph.
76-
graph[i][j] is 1 if there is an edge between vertex i and j.
80+
graph[i][j] is 1 if there is an edge
81+
between vertex i and j.
7782
max_colors (int): Maximum number of colors allowed (m in the m-coloring problem).
7883
colored_vertices (list of int): Current color assignments for each vertex.
79-
-1 indicates that the vertex has not been colored yet.
84+
-1 indicates that the vertex has not been colored
85+
yet.
8086
index (int): The current vertex index being processed.
8187
8288
Returns:
@@ -120,7 +126,8 @@ def util_color(
120126
def color(graph: list[list[int]], max_colors: int) -> list[int]:
121127
"""
122128
Attempts to color the graph with at most max_colors colors such that no two adjacent
123-
vertices have the same color. If it is possible, returns the list of color assignments;
129+
vertices have the same color.
130+
If it is possible, returns the list of color assignments;
124131
otherwise, returns an empty list.
125132
126133
Parameters:
@@ -129,7 +136,8 @@ def color(graph: list[list[int]], max_colors: int) -> list[int]:
129136
130137
Returns:
131138
list of int: List of color assignments if the graph can be colored using max_colors.
132-
Each index in the list represents the color assigned to the corresponding vertex.
139+
Each index in the list represents the color assigned
140+
to the corresponding vertex.
133141
If coloring is not possible, returns an empty list.
134142
135143
Examples:

0 commit comments

Comments
 (0)