Compare commits

...

8 Commits

Author SHA1 Message Date
Scarfinos
733b791ba6
Merge 2cdda8a7b6 into f3f32ae3ca 2024-11-20 11:05:28 +01:00
pre-commit-ci[bot]
f3f32ae3ca
[pre-commit.ci] pre-commit autoupdate (#12385)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.7.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.7.4)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-11-18 22:07:12 +01:00
Christian Clauss
e3bd7721c8
validate_filenames.py Shebang python for Windows (#12371) 2024-11-15 14:59:14 +01:00
Scarfinos
2cdda8a7b6 Merge branch 'scarfinos/basic_graphs' of https://github.com/Scarfinos/Python into scarfinos/basic_graphs 2024-11-06 16:43:41 +01:00
Scarfinos
dcbab8eee9 Solve problem of line too long 2024-11-06 16:43:13 +01:00
pre-commit-ci[bot]
111bd6b6ee [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-11-06 15:35:15 +00:00
Scarfinos
5a8f446281 #9943 : Adding coverage test for basic_graphs.py 2024-11-06 16:31:41 +01:00
Scarfinos
2daf7c3dc6 #9943 : Adding coverage test for basic_graphs.py 2024-11-06 16:17:58 +01:00
3 changed files with 34 additions and 2 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus - id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3 rev: v0.7.4
hooks: hooks:
- id: ruff - id: ruff
- id: ruff-format - id: ruff-format

View File

@ -77,6 +77,14 @@ if __name__ == "__main__":
def dfs(g, s): def dfs(g, s):
"""
>>> dfs({1: [2, 3], 2: [4, 5], 3: [], 4: [], 5: []}, 1)
1
2
4
5
3
"""
vis, _s = {s}, [s] vis, _s = {s}, [s]
print(s) print(s)
while _s: while _s:
@ -104,6 +112,17 @@ def dfs(g, s):
def bfs(g, s): def bfs(g, s):
"""
>>> bfs({1: [2, 3], 2: [4, 5], 3: [6, 7], 4: [], 5: [8], 6: [], 7: [], 8: []}, 1)
1
2
3
4
5
6
7
8
"""
vis, q = {s}, deque([s]) vis, q = {s}, deque([s])
print(s) print(s)
while q: while q:
@ -128,6 +147,19 @@ def bfs(g, s):
def dijk(g, s): def dijk(g, s):
"""
dijk({1: [(2, 7), (3, 9), (6, 14)],
2: [(1, 7), (3, 10), (4, 15)],
3: [(1, 9), (2, 10), (4, 11), (6, 2)],
4: [(2, 15), (3, 11), (5, 6)],
5: [(4, 6), (6, 9)],
6: [(1, 14), (3, 2), (5, 9)]}, 1)
7
9
11
20
20
"""
dist, known, path = {s: 0}, set(), {s: 0} dist, known, path = {s: 0}, set(), {s: 0}
while True: while True:
if len(known) == len(g) - 1: if len(known) == len(g) - 1:

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!python
import os import os
try: try: