Skip to content

Commit

Permalink
린터 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdgua01 committed Sep 17, 2024
1 parent 64cb117 commit 86d16fd
Show file tree
Hide file tree
Showing 38 changed files with 52 additions and 167 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.0
uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1
- name: Install pytest
run: pip install pytest
- name: Test
Expand Down
4 changes: 1 addition & 3 deletions backtracking/escape_maze/escape_maze.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def parse_maze(maze: str) -> Tuple[MAZE, POSITION]:
return maze_info, start_pos


def next_step(
maze: MAZE, current_pos: POSITION, direction: int
) -> Union[POSITION, bool]:
def next_step(maze: MAZE, current_pos: POSITION, direction: int) -> Union[POSITION, bool]:
x, y = current_pos

if direction == 0:
Expand Down
4 changes: 1 addition & 3 deletions backtracking/n_queens/n_queens.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ def is_safe(board: BOARD_TYPE, row: int) -> bool:
current_row = 0

while current_row < row:
if board[current_row] == board[row] or (
abs(board[current_row] - board[row]) == abs(current_row - row)
):
if board[current_row] == board[row] or (abs(board[current_row] - board[row]) == abs(current_row - row)):
return False
current_row += 1
return True
Expand Down
4 changes: 1 addition & 3 deletions backtracking/n_queens/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def test_2_3_queens(self) -> None:

def test_4_queens(self) -> None:
result = n_queens(4)
self.assertEqual(
result, [[(1, 0), (3, 1), (0, 2), (2, 3)], [(2, 0), (0, 1), (3, 2), (1, 3)]]
)
self.assertEqual(result, [[(1, 0), (3, 1), (0, 2), (2, 3)], [(2, 0), (0, 1), (3, 2), (1, 3)]])
self.assertEqual(len(result), 2)

def test_8_queens(self) -> None:
Expand Down
3 changes: 1 addition & 2 deletions coding_test/leetcode/decode_string/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ def test_solution():
assert decode_string("abc3[cd]xyz") == "abccdcdcdxyz"
assert decode_string("100[leetcode]") == "leetcode" * 100
assert (
decode_string("3[z]2[2[y]pq4[2[jk]e1[f]]]ef")
== "zzzyypqjkjkefjkjkefjkjkefjkjkefyypqjkjkefjkjkefjkjkefjkjkefef"
decode_string("3[z]2[2[y]pq4[2[jk]e1[f]]]ef") == "zzzyypqjkjkefjkjkefjkjkefjkjkefyypqjkjkefjkjkefjkjkefjkjkefef"
)
4 changes: 1 addition & 3 deletions coding_test/leetcode/insertion_sort_list/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@

def test_solution():
insertion_sort_list = Solution().insertionSortList
sorted_node = insertion_sort_list(
ListNode(4, ListNode(2, ListNode(1, ListNode(3))))
)
sorted_node = insertion_sort_list(ListNode(4, ListNode(2, ListNode(1, ListNode(3)))))
assert list(node.val for node in sorted_node) == [1, 2, 3, 4]
12 changes: 2 additions & 10 deletions coding_test/leetcode/median_of_two_sorted_arrays/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@ def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
elif 0 < i and nums2[j] < nums1[i - 1]:
imax = i - 1
else:
max_left = (
max(nums1[i - 1], nums2[j - 1])
if i and j
else nums1[i - 1] if i else nums2[j - 1]
)
max_left = max(nums1[i - 1], nums2[j - 1]) if i and j else nums1[i - 1] if i else nums2[j - 1]

if (m + n) % 2 == 1:
return max_left

min_right = (
min(nums1[i], nums2[j])
if i != m and j != n
else nums2[j] if i == m else nums1[i]
)
min_right = min(nums1[i], nums2[j]) if i != m and j != n else nums2[j] if i == m else nums1[i]
return (max_left + min_right) / 2
4 changes: 1 addition & 3 deletions coding_test/leetcode/three_sum/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ def setUp(self) -> None:
self.solution = Solution().threeSum

def test_case_1(self) -> None:
self.assertEqual(
self.solution([-1, 0, 1, 2, -1, -4]), [[-1, 0, 1], [-1, -1, 2]]
)
self.assertEqual(self.solution([-1, 0, 1, 2, -1, -4]), [[-1, 0, 1], [-1, -1, 2]])
10 changes: 1 addition & 9 deletions coding_test/leetcode/ugly_number_3/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@
class Solution:
def nthUglyNumber(self, n: int, a: int, b: int, c: int) -> int:
def fulfilled(num) -> bool:
total = (
num // a
+ num // b
+ num // c
- num // ab
- num // ac
- num // bc
+ num // abc
)
total = num // a + num // b + num // c - num // ab - num // ac - num // bc + num // abc
return total >= n

def lcm(x, y) -> int:
Expand Down
10 changes: 2 additions & 8 deletions coding_test/programmers/analog_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ def solution(h1, m1, s1, h2, m2, s2):
while t1 < datetime.datetime(2024, 8, 31, h2, m2, s2):
s1_angle = t1.second * 360 / 60
m1_angle = (t1.minute * 360 / 60) + (t1.second * 360 / 60 / 60)
h1_angle = (
(t1.hour % 12 * 360 / 12)
+ (t1.minute * 360 / 60 / 12)
+ (t1.second * 360 / 60 / 60 / 12)
)
h1_angle = (t1.hour % 12 * 360 / 12) + (t1.minute * 360 / 60 / 12) + (t1.second * 360 / 60 / 60 / 12)

t1 += datetime.timedelta(seconds=1)

s2_angle = (t1.second * 360 / 60) or 360
m2_angle = (t1.minute * 360 / 60) + (t1.second * 360 / 60 / 60) or 360
h2_angle = (t1.hour % 12 * 360 / 12) + (t1.minute * 360 / 60 / 12) + (
t1.second * 360 / 60 / 60 / 12
) or 360
h2_angle = (t1.hour % 12 * 360 / 12) + (t1.minute * 360 / 60 / 12) + (t1.second * 360 / 60 / 60 / 12) or 360

if s1_angle < m1_angle and s2_angle >= m2_angle:
answer += 1
Expand Down
4 changes: 1 addition & 3 deletions coding_test/programmers/brute_force/number_baseball/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@

class TestCase(unittest.TestCase):
def test_case_1(self) -> None:
self.assertEqual(
solution([[123, 1, 1], [356, 1, 0], [327, 2, 0], [489, 0, 1]]), 2
)
self.assertEqual(solution([[123, 1, 1], [356, 1, 0], [327, 2, 0], [489, 0, 1]]), 2)
5 changes: 1 addition & 4 deletions coding_test/programmers/brute_force/split_electric_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ def solution(n, wires):


def test_cases():
assert (
solution(9, [[1, 3], [2, 3], [3, 4], [4, 5], [4, 6], [4, 7], [7, 8], [7, 9]])
== 3
)
assert solution(9, [[1, 3], [2, 3], [3, 4], [4, 5], [4, 6], [4, 7], [7, 8], [7, 9]]) == 3
assert solution(4, [[1, 2], [2, 3], [3, 4]]) == 0
assert solution(7, [[1, 2], [2, 7], [3, 7], [3, 4], [4, 5], [6, 7]]) == 1
4 changes: 1 addition & 3 deletions coding_test/programmers/dfs_bfs/fill_puzzle_failed.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def extract_polygon(grid, active_value, queue, visited):
x, y, cell = queue.popleft()
for arrow, (dx, dy, n_cell) in xy_distances.items():
nx, ny = x + dx, y + dy
if (0 > nx or nx >= len(grid) or 0 > ny or ny >= len(grid)) or cell[
arrow
] == "1":
if (0 > nx or nx >= len(grid) or 0 > ny or ny >= len(grid)) or cell[arrow] == "1":
continue
if grid[ny][nx] == active_value:
cell = "".join("1" if i == arrow else c for i, c in enumerate(cell))
Expand Down
16 changes: 4 additions & 12 deletions coding_test/programmers/dfs_bfs/network/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,10 @@ def test_case_1(self):
self.assertEqual(solution(3, [[1, 1, 0], [1, 1, 0], [0, 0, 1]]), 2)
self.assertEqual(solution(3, [[1, 1, 0], [1, 1, 1], [0, 1, 1]]), 1)
self.assertEqual(solution(3, [[1, 1, 1], [1, 1, 1], [1, 1, 1]]), 1)
self.assertEqual(
solution(4, [[1, 1, 1, 0], [1, 1, 0, 0], [1, 0, 1, 1], [0, 0, 1, 1]]), 1
)
self.assertEqual(
solution(4, [[1, 1, 1, 0], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]]), 1
)
self.assertEqual(
solution(4, [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]), 4
)
self.assertEqual(
solution(4, [[1, 0, 0, 1], [0, 1, 1, 1], [0, 1, 1, 0], [1, 0, 1, 1]]), 1
)
self.assertEqual(solution(4, [[1, 1, 1, 0], [1, 1, 0, 0], [1, 0, 1, 1], [0, 0, 1, 1]]), 1)
self.assertEqual(solution(4, [[1, 1, 1, 0], [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]]), 1)
self.assertEqual(solution(4, [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]), 4)
self.assertEqual(solution(4, [[1, 0, 0, 1], [0, 1, 1, 1], [0, 1, 1, 0], [1, 0, 1, 1]]), 1)
self.assertEqual(
solution(
5,
Expand Down
15 changes: 3 additions & 12 deletions coding_test/programmers/dfs_bfs/pickup_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,12 @@ def solution(rectangle, character_x, character_y, item_x, item_y):


def test_cases():
assert (
solution([[1, 1, 7, 4], [3, 2, 5, 5], [4, 3, 6, 9], [2, 6, 8, 8]], 1, 3, 7, 8)
== 17
)
assert (
solution([[1, 1, 8, 4], [2, 2, 4, 9], [3, 6, 9, 8], [6, 3, 7, 7]], 9, 7, 6, 1)
== 11
)
assert solution([[1, 1, 7, 4], [3, 2, 5, 5], [4, 3, 6, 9], [2, 6, 8, 8]], 1, 3, 7, 8) == 17
assert solution([[1, 1, 8, 4], [2, 2, 4, 9], [3, 6, 9, 8], [6, 3, 7, 7]], 9, 7, 6, 1) == 11
assert solution([[1, 1, 5, 7]], 1, 1, 4, 7) == 9
assert solution([[2, 1, 7, 5], [6, 4, 10, 10]], 3, 1, 7, 10) == 15
assert solution([[2, 2, 5, 5], [1, 3, 6, 4], [3, 1, 4, 6]], 1, 4, 6, 3) == 10
assert (
solution([[2, 1, 3, 6], [4, 1, 5, 6], [1, 2, 6, 3], [1, 4, 6, 5]], 3, 2, 5, 4)
== 8
)
assert solution([[2, 1, 3, 6], [4, 1, 5, 6], [1, 2, 6, 3], [1, 4, 6, 5]], 3, 2, 5, 4) == 8
assert solution([[1, 1, 4, 4], [2, 2, 5, 5], [3, 3, 7, 8]], 1, 1, 5, 3) == 6
assert solution([[1, 1, 2, 2]], 1, 1, 2, 2) == 2
assert solution([[1, 1, 50, 5]], 1, 1, 50, 5) == 53
4 changes: 1 addition & 3 deletions coding_test/programmers/graph/ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ def solution(n, results):
loses[loser].update(loses[i])
for winner in loses[i]:
wins[winner].update(wins[i])
return sum(
len(winners) + len(losers) == n - 1 for winners, losers in zip(wins, loses)
)
return sum(len(winners) + len(losers) == n - 1 for winners, losers in zip(wins, loses))


def test_cases():
Expand Down
4 changes: 1 addition & 3 deletions coding_test/programmers/hash/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,4 @@ def solution(genres, plays):


def test_cases():
assert solution(
["classic", "pop", "classic", "classic", "pop"], [500, 600, 150, 800, 2500]
) == [4, 1, 3, 0]
assert solution(["classic", "pop", "classic", "classic", "pop"], [500, 600, 150, 800, 2500]) == [4, 1, 3, 0]
9 changes: 2 additions & 7 deletions coding_test/programmers/select_dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

def solution(dice):
data = {
combi: sorted(
sum(dice[v][k] for k, v in zip(x, combi))
for x in product(range(6), repeat=len(combi))
)
combi: sorted(sum(dice[v][k] for k, v in zip(x, combi)) for x in product(range(6), repeat=len(combi)))
for combi in combinations(range(len(dice)), len(dice) // 2)
}
result = {}
Expand All @@ -27,9 +24,7 @@ def solution(dice):


def test_cases():
assert solution(
[[1, 2, 3, 4, 5, 6], [3, 3, 3, 3, 4, 4], [1, 3, 3, 4, 4, 4], [1, 1, 4, 4, 5, 5]]
) == [1, 4]
assert solution([[1, 2, 3, 4, 5, 6], [3, 3, 3, 3, 4, 4], [1, 3, 3, 4, 4, 4], [1, 1, 4, 4, 5, 5]]) == [1, 4]
assert solution([[1, 2, 3, 4, 5, 6], [2, 2, 4, 4, 6, 6]]) == [2]
assert solution(
[
Expand Down
5 changes: 1 addition & 4 deletions coding_test/programmers/sort/kth_number/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@


def solution(array, commands):
return [
sorted(array[command[0] - 1 : command[1]])[command[2] - 1]
for command in commands
]
return [sorted(array[command[0] - 1 : command[1]])[command[2] - 1] for command in commands]
4 changes: 1 addition & 3 deletions coding_test/programmers/stack_queue/truck/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

class UnitTest(unittest.TestCase):
def test_solution(self) -> None:
self.assertEqual(
solution(bridge_length=2, weight=10, truck_weights=[7, 4, 5, 6]), 8
)
self.assertEqual(solution(bridge_length=2, weight=10, truck_weights=[7, 4, 5, 6]), 8)
self.assertEqual(
solution(bridge_length=100, weight=100, truck_weights=[10]),
101,
Expand Down
4 changes: 1 addition & 3 deletions compression/huffman/huffman.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@


class Node(object):
def __init__(
self, value: Union[str, None], bitstring=None, left=None, right=None
) -> None:
def __init__(self, value: Union[str, None], bitstring=None, left=None, right=None) -> None:
self.value = value
self.bitstring: str = bitstring
self.left: Union[Node, None] = left
Expand Down
4 changes: 1 addition & 3 deletions data_structures/graph/adjacency_list/adjacency_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def print_graph(self) -> dict:
if current_vertex.adjacency_list is not None:
__edge = current_vertex.adjacency_list
while __edge is not None:
result[current_vertex.value]["adjacency_list"][
__edge.target.value
] = __edge.weight
result[current_vertex.value]["adjacency_list"][__edge.target.value] = __edge.weight
__edge = __edge.next

current_vertex = current_vertex.next
Expand Down
4 changes: 1 addition & 3 deletions data_structures/graph/adjacency_matrix/adjacency_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def print_graph(self) -> dict:

for __vertex in self.vertices:
result[__vertex.value]["visited"] = __vertex.is_visited
result[__vertex.value]["edges"] = [
(__vertex.index, target) for target in __vertex.edges
]
result[__vertex.value]["edges"] = [(__vertex.index, target) for target in __vertex.edges]
return result

def dfs(self, __vertex: Vertex = None) -> None:
Expand Down
4 changes: 1 addition & 3 deletions data_structures/hash_table/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def test_quadratic_probing(self) -> None:
hash_table.set(14)
hash_table.set(3)
self.assertEqual(hash_table.size, 11)
self.assertEqual(
hash_table.keys, {0: 0, 2: 2, 3: 14, 4: 4, 6: 6, 8: 8, 9: 3, 10: 10}
)
self.assertEqual(hash_table.keys, {0: 0, 2: 2, 3: 14, 4: 4, 6: 6, 8: 8, 9: 3, 10: 10})

def test_double_hashing(self) -> None:
hash_table = DoubleHashingHashTable(7)
Expand Down
5 changes: 1 addition & 4 deletions data_structures/heap/max_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ def remove_max(self):

while left or right:
if left and right:
if (
self.data[current] < self.data[left]
or self.data[current] < self.data[right]
):
if self.data[current] < self.data[left] or self.data[current] < self.data[right]:
if self.data[right] <= self.data[left]:
self.__swap(current, left)
current = left
Expand Down
5 changes: 1 addition & 4 deletions data_structures/heap/min_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ def remove_min(self):

while left or right:
if left and right:
if (
self.data[left] < self.data[current]
or self.data[right] < self.data[current]
):
if self.data[left] < self.data[current] or self.data[right] < self.data[current]:
if self.data[left] <= self.data[right]:
self.__swap(current, left)
current = left
Expand Down
4 changes: 1 addition & 3 deletions data_structures/queue/circular_queue/circular_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ def is_empty(self) -> bool:

@property
def is_full(self) -> bool:
return (
False if self.is_empty else (self.rear + 1) == (self.front + self.capacity)
)
return False if self.is_empty else (self.rear + 1) == (self.front + self.capacity)
5 changes: 1 addition & 4 deletions data_structures/queue/priority_queue/priority_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ def dequeue(self):

while left or right:
if left and right:
if (
self.data[left][1] < self.data[current][1]
or self.data[right][1] < self.data[current][1]
):
if self.data[left][1] < self.data[current][1] or self.data[right][1] < self.data[current][1]:
if self.data[left][1] <= self.data[right][1]:
self.__swap(current, left)
current = left
Expand Down
5 changes: 1 addition & 4 deletions data_structures/stack/calculator/infix_to_postfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ def infix_to_postfix(expression: str) -> list:
else:
if token not in OPERATOR:
raise Exception("허용되지 않은 연산자입니다.")
while (
not operator_stack.is_empty
and OPERATOR[operator_stack.peek()] >= OPERATOR[token]
):
while not operator_stack.is_empty and OPERATOR[operator_stack.peek()] >= OPERATOR[token]:
# 현재 연산자보다 우선순위가 높은 연산자들을 식에 추가
postfix.append(operator_stack.pop())
# 현재 추가되는 연산자가 가장 우선순위가 높은 연산자
Expand Down
10 changes: 2 additions & 8 deletions data_structures/tree/red_black_tree/red_black_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ def insert(self, value):

def remove(self, target):
if target := self.search(target):
if (
target.left == RedBlackTree.empty_node
or target.right == RedBlackTree.empty_node
):
if target.left == RedBlackTree.empty_node or target.right == RedBlackTree.empty_node:
removed = target
else:
removed = self.get_min(target)
Expand Down Expand Up @@ -200,10 +197,7 @@ def remove(self, target):
successor.parent.color = 1
self.left_rotate(successor.parent)
else:
if (
successor.sibling.left.is_black
and successor.sibling.right.is_black
):
if successor.sibling.left.is_black and successor.sibling.right.is_black:
successor.sibling.color = 1
successor = successor.parent
else:
Expand Down
Loading

0 comments on commit 86d16fd

Please sign in to comment.