Skip to content

update fork #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2021
Merged
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
18 changes: 10 additions & 8 deletions matrix/rotate_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
https://stackoverflow.com/questions/42519/how-do-you-rotate-a-two-dimensional-array
"""

from __future__ import annotations

def make_matrix(row_size: int = 4) -> [[int]]:

def make_matrix(row_size: int = 4) -> list[list]:
"""
>>> make_matrix()
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
Expand All @@ -23,7 +25,7 @@ def make_matrix(row_size: int = 4) -> [[int]]:
return [[1 + x + y * row_size for x in range(row_size)] for y in range(row_size)]


def rotate_90(matrix: [[]]) -> [[]]:
def rotate_90(matrix: list[list]) -> list[list]:
"""
>>> rotate_90(make_matrix())
[[4, 8, 12, 16], [3, 7, 11, 15], [2, 6, 10, 14], [1, 5, 9, 13]]
Expand All @@ -35,7 +37,7 @@ def rotate_90(matrix: [[]]) -> [[]]:
# OR.. transpose(reverse_column(matrix))


def rotate_180(matrix: [[]]) -> [[]]:
def rotate_180(matrix: list[list]) -> list[list]:
"""
>>> rotate_180(make_matrix())
[[16, 15, 14, 13], [12, 11, 10, 9], [8, 7, 6, 5], [4, 3, 2, 1]]
Expand All @@ -47,7 +49,7 @@ def rotate_180(matrix: [[]]) -> [[]]:
# OR.. reverse_column(reverse_row(matrix))


def rotate_270(matrix: [[]]) -> [[]]:
def rotate_270(matrix: list[list]) -> list[list]:
"""
>>> rotate_270(make_matrix())
[[13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]]
Expand All @@ -59,22 +61,22 @@ def rotate_270(matrix: [[]]) -> [[]]:
# OR.. transpose(reverse_row(matrix))


def transpose(matrix: [[]]) -> [[]]:
def transpose(matrix: list[list]) -> list[list]:
matrix[:] = [list(x) for x in zip(*matrix)]
return matrix


def reverse_row(matrix: [[]]) -> [[]]:
def reverse_row(matrix: list[list]) -> list[list]:
matrix[:] = matrix[::-1]
return matrix


def reverse_column(matrix: [[]]) -> [[]]:
def reverse_column(matrix: list[list]) -> list[list]:
matrix[:] = [x[::-1] for x in matrix]
return matrix


def print_matrix(matrix: [[]]) -> [[]]:
def print_matrix(matrix: list[list]) -> None:
for i in matrix:
print(*i)

Expand Down
2 changes: 1 addition & 1 deletion matrix/tests/test_matrix_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import sys

import numpy as np
import pytest
import pytest # type: ignore

# Custom/local libraries
from matrix import matrix_operation as matop
Expand Down
3 changes: 2 additions & 1 deletion sorts/shell_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def shell_sort(collection):
while j >= gap and collection[j - gap] > insert_value:
collection[j] = collection[j - gap]
j -= gap
collection[j] = insert_value
if j != i:
collection[j] = insert_value
return collection


Expand Down