Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions backtracking/m-coloring-problem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
def isSafe(node, color, graph, n, col):

Check failure on line 1 in backtracking/m-coloring-problem.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N802)

backtracking/m-coloring-problem.py:1:5: N802 Function name `isSafe` should be lowercase

Check failure on line 1 in backtracking/m-coloring-problem.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N999)

backtracking/m-coloring-problem.py:1:1: N999 Invalid module name: 'm-coloring-problem'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: isSafe. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file backtracking/m-coloring-problem.py, please provide doctest for the function isSafe

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: isSafe

Please provide type hint for the parameter: node

Please provide type hint for the parameter: color

Please provide type hint for the parameter: graph

Please provide descriptive name for the parameter: n

Please provide type hint for the parameter: n

Please provide type hint for the parameter: col

for k in range(n):
if graph[node][k] == 1 and col[k] == color:
return False
return True

Check failure on line 5 in backtracking/m-coloring-problem.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (SIM110)

backtracking/m-coloring-problem.py:2:5: SIM110 Use `return all(not (graph[node][k] == 1 and col[k] == color) for k in range(n))` instead of `for` loop


def solve(node, col, m, n, graph):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: solve. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file backtracking/m-coloring-problem.py, please provide doctest for the function solve

Please provide type hint for the parameter: node

Please provide type hint for the parameter: col

Please provide descriptive name for the parameter: m

Please provide type hint for the parameter: m

Please provide descriptive name for the parameter: n

Please provide type hint for the parameter: n

Please provide type hint for the parameter: graph

if node == n:
return True
for c in range(1, m + 1):
if isSafe(node, c, graph, n, col):
col[node] = c
if solve(node + 1, col, m, n, graph):
return True
col[node] = 0
return False


def graphColoring(graph, m, n):

Check failure on line 20 in backtracking/m-coloring-problem.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N802)

backtracking/m-coloring-problem.py:20:5: N802 Function name `graphColoring` should be lowercase
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: graphColoring. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file backtracking/m-coloring-problem.py, please provide doctest for the function graphColoring

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: graphColoring

Please provide type hint for the parameter: graph

Please provide descriptive name for the parameter: m

Please provide type hint for the parameter: m

Please provide descriptive name for the parameter: n

Please provide type hint for the parameter: n

col = [0] * n
if solve(0, col, m, n, graph):
return True
return False

Check failure on line 24 in backtracking/m-coloring-problem.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (SIM103)

backtracking/m-coloring-problem.py:22:5: SIM103 Return the condition `bool(solve(0, col, m, n, graph))` directly


if __name__ == "__main__":
V = int(input())
E = int(input())
graph = [[0 for _ in range(V)] for _ in range(V)]
for _ in range(E):
u, v = map(int, input().split())
graph[u][v] = 1
graph[v][u] = 1
m = int(input())
if graphColoring(graph, m, V):
print("True")
else:
print("False")
89 changes: 89 additions & 0 deletions other/calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from flask import Flask, request, render_template_string

Check failure on line 1 in other/calc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

other/calc.py:1:1: I001 Import block is un-sorted or un-formatted

app = Flask(__name__)


def calculate(num1: float, num2: float, operation: str) -> float:
"""
Perform basic arithmetic operations: add, subtract, multiply, divide.

>>> calculate(2, 3, 'add')
5
>>> calculate(5, 3, 'subtract')
2
>>> calculate(4, 2, 'multiply')
8
>>> calculate(10, 2, 'divide')
5.0
>>> calculate(5, 0, 'divide')
Traceback (most recent call last):
...
ValueError: Division by zero is not allowed.
"""
if operation == "add":
return num1 + num2
elif operation == "subtract":
return num1 - num2
elif operation == "multiply":
return num1 * num2
elif operation == "divide":
if num2 == 0:
raise ValueError("Division by zero is not allowed.")
return num1 / num2
else:
raise ValueError(f"Unknown operation: {operation}")

Check failure on line 34 in other/calc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (EM102)

other/calc.py:34:26: EM102 Exception must not use an f-string literal, assign to variable first


# HTML template for the web interface
template = """
<!DOCTYPE html>
<html>
<head>
<title>Flask Calculator</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; padding: 50px; background: #f7f7f7; }

Check failure on line 44 in other/calc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/calc.py:44:89: E501 Line too long (104 > 88)
input, select { padding: 10px; margin: 5px; width: 150px; }
input[type=submit] { width: auto; cursor: pointer; }
.result { margin-top: 20px; font-size: 1.5em; color: #27ae60; }
h1 { color: #2c3e50; }
</style>
</head>
<body>
<h1>Flask Calculator</h1>
<form method="POST">
<input type="number" name="num1" step="any" placeholder="First Number" required>
<input type="number" name="num2" step="any" placeholder="Second Number" required>

Check failure on line 55 in other/calc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/calc.py:55:89: E501 Line too long (89 > 88)
<br>
<select name="operation">
<option value="add">Add (+)</option>
<option value="subtract">Subtract (-)</option>
<option value="multiply">Multiply (×)</option>

Check failure on line 60 in other/calc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (RUF001)

other/calc.py:60:48: RUF001 String contains ambiguous `×` (MULTIPLICATION SIGN). Did you mean `x` (LATIN SMALL LETTER X)?
<option value="divide">Divide (÷)</option>
</select>
<br>
<input type="submit" value="Calculate">
</form>
{% if result is not none %}
<div class="result">Result: {{ result }}</div>
{% endif %}
</body>
</html>
"""


@app.route("/", methods=["GET", "POST"])
def home():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: home. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file other/calc.py, please provide doctest for the function home

result = None
if request.method == "POST":
try:
num1 = float(request.form["num1"])
num2 = float(request.form["num2"])
op = request.form["operation"]
result = calculate(num1, num2, op)
except Exception as e:
result = str(e)
return render_template_string(template, result=result)


if __name__ == "__main__":
app.run(debug=True)
Loading