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
2 changes: 1 addition & 1 deletion computer_vision/mean_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def mean_threshold(image: Image.Image) -> Image.Image:

for j in range(width):
for i in range(height):
pixels[i, j] = 255 if pixels[i, j] > mean else 0
image.putpixel((i, j), 255 if pixels[i, j] > mean else 0)
return image


Expand Down
6 changes: 6 additions & 0 deletions other/dancing_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
class DLXNode:
"""Represents a node in the Dancing Links structure."""

left: "DLXNode"
right: "DLXNode"
up: "DLXNode"
down: "DLXNode"
column: "ColumnNode | None"

def __init__(self) -> None:
self.left = self.right = self.up = self.down = self
self.column = None
Expand Down
7 changes: 6 additions & 1 deletion sorts/benchmark_sorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,30 @@

import random
import sys
from collections.abc import Callable, Sequence

Check failure on line 23 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F401)

sorts/benchmark_sorts.py:23:29: F401 `collections.abc.Callable` imported but unused help: Remove unused import: `collections.abc.Callable`
from itertools import pairwise
from timeit import timeit
from typing import Protocol


class SortFunction(Protocol):
def __call__[T](self, collection: list[T], /) -> Sequence[T]: ...


from sorts.bubble_sort import bubble_sort_iterative

Check failure on line 33 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

sorts/benchmark_sorts.py:33:1: E402 Module level import not at top of file help: Move module level imports to top of file
from sorts.cocktail_shaker_sort import cocktail_shaker_sort

Check failure on line 34 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

sorts/benchmark_sorts.py:34:1: E402 Module level import not at top of file help: Move module level imports to top of file
from sorts.comb_sort import comb_sort

Check failure on line 35 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

sorts/benchmark_sorts.py:35:1: E402 Module level import not at top of file help: Move module level imports to top of file
from sorts.gnome_sort import gnome_sort

Check failure on line 36 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

sorts/benchmark_sorts.py:36:1: E402 Module level import not at top of file help: Move module level imports to top of file
from sorts.heap_sort import heap_sort

Check failure on line 37 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

sorts/benchmark_sorts.py:37:1: E402 Module level import not at top of file help: Move module level imports to top of file
from sorts.insertion_sort import insertion_sort

Check failure on line 38 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

sorts/benchmark_sorts.py:38:1: E402 Module level import not at top of file help: Move module level imports to top of file
from sorts.merge_sort import merge_sort

Check failure on line 39 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

sorts/benchmark_sorts.py:39:1: E402 Module level import not at top of file help: Move module level imports to top of file
from sorts.quick_sort import quick_sort

Check failure on line 40 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

sorts/benchmark_sorts.py:40:1: E402 Module level import not at top of file help: Move module level imports to top of file
from sorts.selection_sort import selection_sort

Check failure on line 41 in sorts/benchmark_sorts.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

sorts/benchmark_sorts.py:41:1: E402 Module level import not at top of file help: Move module level imports to top of file
from sorts.shell_sort import shell_sort
from sorts.tim_sort import tim_sort

# name -> callable. Every callable accepts a list and returns the sorted list.
SORTS: dict[str, Callable[[list[int]], Sequence[int]]] = {
SORTS: dict[str, SortFunction] = {
"bubble_sort": bubble_sort_iterative,
"cocktail_shaker_sort": cocktail_shaker_sort,
"comb_sort": comb_sort,
Expand Down
Loading