diff --git a/.travis.yml b/.travis.yml index 21103c3570d3..24d44213ac2f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ notifications: on_success: never before_script: - black --check . || true - - flake8 --ignore=E203,W503 --max-complexity=25 --max-line-length=88 --statistics --count . + - flake8 --ignore=E203,W503 --max-complexity=15 --max-line-length=88 --statistics --count . - scripts/validate_filenames.py # no uppercase, no spaces, in a directory - pip install -r requirements.txt # fast fail on black, flake8, validate_filenames script: diff --git a/DIRECTORY.md b/DIRECTORY.md index 4ffd20da58de..a12ed78d64f2 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -16,6 +16,7 @@ * [All Subsequences](https://github.com/TheAlgorithms/Python/blob/master/backtracking/all_subsequences.py) * [Coloring](https://github.com/TheAlgorithms/Python/blob/master/backtracking/coloring.py) * [Hamiltonian Cycle](https://github.com/TheAlgorithms/Python/blob/master/backtracking/hamiltonian_cycle.py) + * [Knight Tour](https://github.com/TheAlgorithms/Python/blob/master/backtracking/knight_tour.py) * [Minimax](https://github.com/TheAlgorithms/Python/blob/master/backtracking/minimax.py) * [N Queens](https://github.com/TheAlgorithms/Python/blob/master/backtracking/n_queens.py) * [Rat In Maze](https://github.com/TheAlgorithms/Python/blob/master/backtracking/rat_in_maze.py) @@ -71,6 +72,8 @@ ## Compression * [Burrows Wheeler](https://github.com/TheAlgorithms/Python/blob/master/compression/burrows_wheeler.py) * [Huffman](https://github.com/TheAlgorithms/Python/blob/master/compression/huffman.py) + * [Lempel Ziv](https://github.com/TheAlgorithms/Python/blob/master/compression/lempel_ziv.py) + * [Lempel Ziv Decompress](https://github.com/TheAlgorithms/Python/blob/master/compression/lempel_ziv_decompress.py) * [Peak Signal To Noise Ratio](https://github.com/TheAlgorithms/Python/blob/master/compression/peak_signal_to_noise_ratio.py) ## Computer Vision @@ -199,6 +202,7 @@ * [Longest Increasing Subsequence O(Nlogn)](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/longest_increasing_subsequence_o(nlogn).py) * [Longest Sub Array](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/longest_sub_array.py) * [Matrix Chain Order](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/matrix_chain_order.py) + * [Max Non Adjacent Sum](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/max_non_adjacent_sum.py) * [Max Sub Array](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/max_sub_array.py) * [Max Sum Contiguous Subsequence](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/max_sum_contiguous_subsequence.py) * [Minimum Partition](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/minimum_partition.py) diff --git a/backtracking/knight_tour.py b/backtracking/knight_tour.py index 7d1e03b837e9..e4a93fbc2105 100644 --- a/backtracking/knight_tour.py +++ b/backtracking/knight_tour.py @@ -4,12 +4,12 @@ def get_valid_pos(position: Tuple[int], n: int) -> List[Tuple[int]]: - ''' + """ Find all the valid positions a knight can move to from the current position. >>> get_valid_pos((1, 3), 4) [(2, 1), (0, 1), (3, 2)] - ''' + """ y, x = position positions = [ @@ -20,7 +20,7 @@ def get_valid_pos(position: Tuple[int], n: int) -> List[Tuple[int]]: (y + 2, x + 1), (y + 2, x - 1), (y - 2, x + 1), - (y - 2, x - 1) + (y - 2, x - 1), ] permissible_positions = [] @@ -33,7 +33,7 @@ def get_valid_pos(position: Tuple[int], n: int) -> List[Tuple[int]]: def is_complete(board: List[List[int]]) -> bool: - ''' + """ Check if the board (matrix) has been completely filled with non-zero values. >>> is_complete([[1]]) @@ -41,15 +41,15 @@ def is_complete(board: List[List[int]]) -> bool: >>> is_complete([[1, 2], [3, 0]]) False - ''' + """ return not any(elem == 0 for row in board for elem in row) def open_knight_tour_helper(board: List[List[int]], pos: Tuple[int], curr: int) -> bool: - ''' + """ Helper function to solve knight tour problem. - ''' + """ if is_complete(board): return True @@ -67,7 +67,7 @@ def open_knight_tour_helper(board: List[List[int]], pos: Tuple[int], curr: int) def open_knight_tour(n: int) -> List[List[int]]: - ''' + """ Find the solution for the knight tour problem for a board of size n. Raises ValueError if the tour cannot be performed for the given size. @@ -78,7 +78,7 @@ def open_knight_tour(n: int) -> List[List[int]]: Traceback (most recent call last): ... ValueError: Open Kight Tour cannot be performed on a board of size 2 - ''' + """ board = [[0 for i in range(n)] for j in range(n)] diff --git a/dynamic_programming/max_non_adjacent_sum.py b/dynamic_programming/max_non_adjacent_sum.py index 1d771f21f3fb..b9f99a226bd9 100644 --- a/dynamic_programming/max_non_adjacent_sum.py +++ b/dynamic_programming/max_non_adjacent_sum.py @@ -4,7 +4,7 @@ def maximum_non_adjacent_sum(nums: List[int]) -> int: - ''' + """ Find the maximum non-adjacent sum of the integers in the nums input list >>> print(maximum_non_adjacent_sum([1, 2, 3])) @@ -15,14 +15,15 @@ def maximum_non_adjacent_sum(nums: List[int]) -> int: 0 >>> maximum_non_adjacent_sum([499, 500, -3, -7, -2, -2, -6]) 500 - ''' + """ if not nums: return 0 max_including = nums[0] max_excluding = 0 for num in nums[1:]: max_including, max_excluding = ( - max_excluding + num, max(max_including, max_excluding) + max_excluding + num, + max(max_including, max_excluding), ) return max(max_excluding, max_including)