Skip to content

Commit 9316e7c

Browse files
cclaussgithub-actions
andauthored
Set the Python file maximum line length to 88 characters (TheAlgorithms#2122)
* flake8 --max-line-length=88 * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 9438c6b commit 9316e7c

File tree

90 files changed

+474
-321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+474
-321
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ notifications:
1010
on_success: never
1111
before_script:
1212
- black --check . || true
13-
- flake8 --ignore=E203,W503 --max-complexity=25 --max-line-length=120 --statistics --count .
13+
- flake8 --ignore=E203,W503 --max-complexity=25 --max-line-length=88 --statistics --count .
1414
- scripts/validate_filenames.py # no uppercase, no spaces, in a directory
1515
- pip install -r requirements.txt # fast fail on black, flake8, validate_filenames
1616
script:

arithmetic_analysis/intersection.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import math
22

33

4-
def intersection(
5-
function, x0, x1
6-
): # function is the f we want to find its root and x0 and x1 are two random starting points
4+
def intersection(function, x0, x1):
5+
"""
6+
function is the f we want to find its root
7+
x0 and x1 are two random starting points
8+
"""
79
x_n = x0
810
x_n1 = x1
911
while True:

backtracking/hamiltonian_cycle.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def valid_connection(
1616
Checks whether it is possible to add next into path by validating 2 statements
1717
1. There should be path between current and next vertex
1818
2. Next vertex should not be in path
19-
If both validations succeeds we return true saying that it is possible to connect this vertices
20-
either we return false
19+
If both validations succeeds we return True saying that it is possible to connect
20+
this vertices either we return False
2121
2222
Case 1:Use exact graph as in main function, with initialized values
2323
>>> graph = [[0, 1, 0, 1, 0],
@@ -52,7 +52,8 @@ def util_hamilton_cycle(graph: List[List[int]], path: List[int], curr_ind: int)
5252
Pseudo-Code
5353
Base Case:
5454
1. Chceck if we visited all of vertices
55-
1.1 If last visited vertex has path to starting vertex return True either return False
55+
1.1 If last visited vertex has path to starting vertex return True either
56+
return False
5657
Recursive Step:
5758
2. Iterate over each vertex
5859
Check if next vertex is valid for transiting from current vertex
@@ -74,7 +75,8 @@ def util_hamilton_cycle(graph: List[List[int]], path: List[int], curr_ind: int)
7475
>>> print(path)
7576
[0, 1, 2, 4, 3, 0]
7677
77-
Case 2: Use exact graph as in previous case, but in the properties taken from middle of calculation
78+
Case 2: Use exact graph as in previous case, but in the properties taken from
79+
middle of calculation
7880
>>> graph = [[0, 1, 0, 1, 0],
7981
... [1, 0, 1, 1, 1],
8082
... [0, 1, 0, 0, 1],

backtracking/n_queens.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
def isSafe(board, row, column):
1414
"""
15-
This function returns a boolean value True if it is safe to place a queen there considering
16-
the current state of the board.
15+
This function returns a boolean value True if it is safe to place a queen there
16+
considering the current state of the board.
1717
1818
Parameters :
1919
board(2D matrix) : board
@@ -56,8 +56,8 @@ def solve(board, row):
5656
return
5757
for i in range(len(board)):
5858
"""
59-
For every row it iterates through each column to check if it is feasible to place a
60-
queen there.
59+
For every row it iterates through each column to check if it is feasible to
60+
place a queen there.
6161
If all the combinations for that particular branch are successful the board is
6262
reinitialized for the next possible combination.
6363
"""

backtracking/sum_of_subsets.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""
2-
The sum-of-subsetsproblem states that a set of non-negative integers, and a value M,
3-
determine all possible subsets of the given set whose summation sum equal to given M.
2+
The sum-of-subsetsproblem states that a set of non-negative integers, and a
3+
value M, determine all possible subsets of the given set whose summation sum
4+
equal to given M.
45
5-
Summation of the chosen numbers must be equal to given number M and one number can
6-
be used only once.
6+
Summation of the chosen numbers must be equal to given number M and one number
7+
can be used only once.
78
"""
89

910

@@ -21,7 +22,8 @@ def create_state_space_tree(nums, max_sum, num_index, path, result, remaining_nu
2122
Creates a state space tree to iterate through each branch using DFS.
2223
It terminates the branching of a node when any of the two conditions
2324
given below satisfy.
24-
This algorithm follows depth-fist-search and backtracks when the node is not branchable.
25+
This algorithm follows depth-fist-search and backtracks when the node is not
26+
branchable.
2527
2628
"""
2729
if sum(path) > max_sum or (remaining_nums_sum + sum(path)) < max_sum:

blockchain/chinese_remainder_theorem.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Chinese Remainder Theorem:
22
# GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor )
33

4-
# If GCD(a,b) = 1, then for any remainder ra modulo a and any remainder rb modulo b there exists integer n,
5-
# such that n = ra (mod a) and n = ra(mod b). If n1 and n2 are two such integers, then n1=n2(mod ab)
4+
# If GCD(a,b) = 1, then for any remainder ra modulo a and any remainder rb modulo b
5+
# there exists integer n, such that n = ra (mod a) and n = ra(mod b). If n1 and n2 are
6+
# two such integers, then n1=n2(mod ab)
67

78
# Algorithm :
89

blockchain/diophantine_equation.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Diophantine Equation : Given integers a,b,c ( at least one of a and b != 0), the diophantine equation
2-
# a*x + b*y = c has a solution (where x and y are integers) iff gcd(a,b) divides c.
1+
# Diophantine Equation : Given integers a,b,c ( at least one of a and b != 0), the
2+
# diophantine equation a*x + b*y = c has a solution (where x and y are integers)
3+
# iff gcd(a,b) divides c.
34

45
# GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor )
56

@@ -29,8 +30,9 @@ def diophantine(a, b, c):
2930

3031
# Finding All solutions of Diophantine Equations:
3132

32-
# Theorem : Let gcd(a,b) = d, a = d*p, b = d*q. If (x0,y0) is a solution of Diophantine Equation a*x + b*y = c.
33-
# a*x0 + b*y0 = c, then all the solutions have the form a(x0 + t*q) + b(y0 - t*p) = c, where t is an arbitrary integer.
33+
# Theorem : Let gcd(a,b) = d, a = d*p, b = d*q. If (x0,y0) is a solution of Diophantine
34+
# Equation a*x + b*y = c. a*x0 + b*y0 = c, then all the solutions have the form
35+
# a(x0 + t*q) + b(y0 - t*p) = c, where t is an arbitrary integer.
3436

3537
# n is the number of solution you want, n = 2 by default
3638

@@ -75,8 +77,9 @@ def greatest_common_divisor(a, b):
7577
>>> greatest_common_divisor(7,5)
7678
1
7779
78-
Note : In number theory, two integers a and b are said to be relatively prime, mutually prime, or co-prime
79-
if the only positive integer (factor) that divides both of them is 1 i.e., gcd(a,b) = 1.
80+
Note : In number theory, two integers a and b are said to be relatively prime,
81+
mutually prime, or co-prime if the only positive integer (factor) that
82+
divides both of them is 1 i.e., gcd(a,b) = 1.
8083
8184
>>> greatest_common_divisor(121, 11)
8285
11
@@ -91,7 +94,8 @@ def greatest_common_divisor(a, b):
9194
return b
9295

9396

94-
# Extended Euclid's Algorithm : If d divides a and b and d = a*x + b*y for integers x and y, then d = gcd(a,b)
97+
# Extended Euclid's Algorithm : If d divides a and b and d = a*x + b*y for integers
98+
# x and y, then d = gcd(a,b)
9599

96100

97101
def extended_gcd(a, b):

blockchain/modular_division.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
# GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor )
55

6-
# Given three integers a, b, and n, such that gcd(a,n)=1 and n>1, the algorithm should return an integer x such that
7-
# 0≤x≤n−1, and b/a=x(modn) (that is, b=ax(modn)).
6+
# Given three integers a, b, and n, such that gcd(a,n)=1 and n>1, the algorithm should
7+
# return an integer x such that 0≤x≤n−1, and b/a=x(modn) (that is, b=ax(modn)).
88

99
# Theorem:
1010
# a has a multiplicative inverse modulo n iff gcd(a,n) = 1
@@ -68,7 +68,8 @@ def modular_division2(a, b, n):
6868
return x
6969

7070

71-
# Extended Euclid's Algorithm : If d divides a and b and d = a*x + b*y for integers x and y, then d = gcd(a,b)
71+
# Extended Euclid's Algorithm : If d divides a and b and d = a*x + b*y for integers x
72+
# and y, then d = gcd(a,b)
7273

7374

7475
def extended_gcd(a, b):
@@ -123,8 +124,9 @@ def greatest_common_divisor(a, b):
123124
>>> greatest_common_divisor(7,5)
124125
1
125126
126-
Note : In number theory, two integers a and b are said to be relatively prime, mutually prime, or co-prime
127-
if the only positive integer (factor) that divides both of them is 1 i.e., gcd(a,b) = 1.
127+
Note : In number theory, two integers a and b are said to be relatively prime,
128+
mutually prime, or co-prime if the only positive integer (factor) that divides
129+
both of them is 1 i.e., gcd(a,b) = 1.
128130
129131
>>> greatest_common_divisor(121, 11)
130132
11

ciphers/affine_cipher.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def check_keys(keyA, keyB, mode):
5555

5656
def encrypt_message(key: int, message: str) -> str:
5757
"""
58-
>>> encrypt_message(4545, 'The affine cipher is a type of monoalphabetic substitution cipher.')
58+
>>> encrypt_message(4545, 'The affine cipher is a type of monoalphabetic '
59+
... 'substitution cipher.')
5960
'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF{xIp~{HL}Gi'
6061
"""
6162
keyA, keyB = divmod(key, len(SYMBOLS))
@@ -72,7 +73,8 @@ def encrypt_message(key: int, message: str) -> str:
7273

7374
def decrypt_message(key: int, message: str) -> str:
7475
"""
75-
>>> decrypt_message(4545, 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF{xIp~{HL}Gi')
76+
>>> decrypt_message(4545, 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF'
77+
... '{xIp~{HL}Gi')
7678
'The affine cipher is a type of monoalphabetic substitution cipher.'
7779
"""
7880
keyA, keyB = divmod(key, len(SYMBOLS))

ciphers/base64_cipher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def decode_base64(text):
3939
'WELCOME to base64 encoding 😁'
4040
>>> decode_base64('QcOF4ZCD8JCAj/CfpJM=')
4141
'AÅᐃ𐀏🤓'
42-
>>> decode_base64("QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB\r\nQUFB")
42+
>>> decode_base64("QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUF"
43+
... "BQUFBQUFBQUFB\r\nQUFB")
4344
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
4445
"""
4546
base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

0 commit comments

Comments
 (0)