Skip to content

Commit c5bb2b7

Browse files
github-actionsgithub-actions
github-actions
authored and
github-actions
committed
fixup! Format Python code with psf/black push
1 parent 1a38679 commit c5bb2b7

File tree

85 files changed

+896
-900
lines changed

Some content is hidden

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

85 files changed

+896
-900
lines changed

arithmetic_analysis/newton_raphson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def newton_raphson(func: str, a: int, precision: int = 10 ** -10) -> float:
12-
""" Finds root from the point 'a' onwards by Newton-Raphson method
12+
"""Finds root from the point 'a' onwards by Newton-Raphson method
1313
>>> newton_raphson("sin(x)", 2)
1414
3.1415926536808043
1515
>>> newton_raphson("x**2 - 5*x +2", 0.4)

backtracking/all_permutations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def generate_all_permutations(sequence):
1313

1414
def create_state_space_tree(sequence, current_sequence, index, index_used):
1515
"""
16-
Creates a state space tree to iterate through each branch using DFS.
17-
We know that each state has exactly len(sequence) - index children.
18-
It terminates when it reaches the end of the given sequence.
19-
"""
16+
Creates a state space tree to iterate through each branch using DFS.
17+
We know that each state has exactly len(sequence) - index children.
18+
It terminates when it reaches the end of the given sequence.
19+
"""
2020

2121
if index == len(sequence):
2222
print(current_sequence)

backtracking/all_subsequences.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def generate_all_subsequences(sequence):
1313

1414
def create_state_space_tree(sequence, current_subsequence, index):
1515
"""
16-
Creates a state space tree to iterate through each branch using DFS.
17-
We know that each state has exactly two children.
18-
It terminates when it reaches the end of the given sequence.
19-
"""
16+
Creates a state space tree to iterate through each branch using DFS.
17+
We know that each state has exactly two children.
18+
It terminates when it reaches the end of the given sequence.
19+
"""
2020

2121
if index == len(sequence):
2222
print(current_subsequence)

backtracking/n_queens.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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
15+
This function returns a boolean value True if it is safe to place a queen there considering
1616
the current state of the board.
1717
1818
Parameters :
@@ -40,13 +40,13 @@ def isSafe(board, row, column):
4040

4141
def solve(board, row):
4242
"""
43-
It creates a state space tree and calls the safe function until it receives a
44-
False Boolean and terminates that branch and backtracks to the next
43+
It creates a state space tree and calls the safe function until it receives a
44+
False Boolean and terminates that branch and backtracks to the next
4545
poosible solution branch.
4646
"""
4747
if row >= len(board):
4848
"""
49-
If the row number exceeds N we have board with a successful combination
49+
If the row number exceeds N we have board with a successful combination
5050
and that combination is appended to the solution list and the board is printed.
5151
5252
"""
@@ -56,9 +56,9 @@ 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 feesible to place a
59+
For every row it iterates through each column to check if it is feesible to place a
6060
queen there.
61-
If all the combinations for that particular branch are successful the board is
61+
If all the combinations for that particular branch are successful the board is
6262
reinitialized for the next possible combination.
6363
"""
6464
if isSafe(board, row, i):

backtracking/sudoku.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def sudoku(grid):
105105
[7, 4, 5, 2, 8, 6, 3, 1, 9]]
106106
>>> sudoku(no_solution)
107107
False
108-
"""
108+
"""
109109

110110
if is_completed(grid):
111111
return grid

backtracking/sum_of_subsets.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ def generate_sum_of_subsets_soln(nums, max_sum):
1818

1919
def create_state_space_tree(nums, max_sum, num_index, path, result, remaining_nums_sum):
2020
"""
21-
Creates a state space tree to iterate through each branch using DFS.
22-
It terminates the branching of a node when any of the two conditions
23-
given below satisfy.
24-
This algorithm follows depth-fist-search and backtracks when the node is not branchable.
21+
Creates a state space tree to iterate through each branch using DFS.
22+
It terminates the branching of a node when any of the two conditions
23+
given below satisfy.
24+
This algorithm follows depth-fist-search and backtracks when the node is not branchable.
2525
26-
"""
26+
"""
2727
if sum(path) > max_sum or (remaining_nums_sum + sum(path)) < max_sum:
2828
return
2929
if sum(path) == max_sum:

blockchain/modular_division.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ def modular_division2(a, b, n):
7373

7474
def extended_gcd(a, b):
7575
"""
76-
>>> extended_gcd(10, 6)
77-
(2, -1, 2)
76+
>>> extended_gcd(10, 6)
77+
(2, -1, 2)
7878
79-
>>> extended_gcd(7, 5)
80-
(1, -2, 3)
79+
>>> extended_gcd(7, 5)
80+
(1, -2, 3)
8181
82-
** extended_gcd function is used when d = gcd(a,b) is required in output
82+
** extended_gcd function is used when d = gcd(a,b) is required in output
8383
8484
"""
8585
assert a >= 0 and b >= 0

ciphers/xor_cipher.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121
class XORCipher:
2222
def __init__(self, key=0):
2323
"""
24-
simple constructor that receives a key or uses
25-
default key = 0
26-
"""
24+
simple constructor that receives a key or uses
25+
default key = 0
26+
"""
2727

2828
# private field
2929
self.__key = key
3030

3131
def encrypt(self, content, key):
3232
"""
33-
input: 'content' of type string and 'key' of type int
34-
output: encrypted string 'content' as a list of chars
35-
if key not passed the method uses the key by the constructor.
36-
otherwise key = 1
37-
"""
33+
input: 'content' of type string and 'key' of type int
34+
output: encrypted string 'content' as a list of chars
35+
if key not passed the method uses the key by the constructor.
36+
otherwise key = 1
37+
"""
3838

3939
# precondition
4040
assert isinstance(key, int) and isinstance(content, str)
@@ -55,11 +55,11 @@ def encrypt(self, content, key):
5555

5656
def decrypt(self, content, key):
5757
"""
58-
input: 'content' of type list and 'key' of type int
59-
output: decrypted string 'content' as a list of chars
60-
if key not passed the method uses the key by the constructor.
61-
otherwise key = 1
62-
"""
58+
input: 'content' of type list and 'key' of type int
59+
output: decrypted string 'content' as a list of chars
60+
if key not passed the method uses the key by the constructor.
61+
otherwise key = 1
62+
"""
6363

6464
# precondition
6565
assert isinstance(key, int) and isinstance(content, list)
@@ -80,11 +80,11 @@ def decrypt(self, content, key):
8080

8181
def encrypt_string(self, content, key=0):
8282
"""
83-
input: 'content' of type string and 'key' of type int
84-
output: encrypted string 'content'
85-
if key not passed the method uses the key by the constructor.
86-
otherwise key = 1
87-
"""
83+
input: 'content' of type string and 'key' of type int
84+
output: encrypted string 'content'
85+
if key not passed the method uses the key by the constructor.
86+
otherwise key = 1
87+
"""
8888

8989
# precondition
9090
assert isinstance(key, int) and isinstance(content, str)
@@ -105,11 +105,11 @@ def encrypt_string(self, content, key=0):
105105

106106
def decrypt_string(self, content, key=0):
107107
"""
108-
input: 'content' of type string and 'key' of type int
109-
output: decrypted string 'content'
110-
if key not passed the method uses the key by the constructor.
111-
otherwise key = 1
112-
"""
108+
input: 'content' of type string and 'key' of type int
109+
output: decrypted string 'content'
110+
if key not passed the method uses the key by the constructor.
111+
otherwise key = 1
112+
"""
113113

114114
# precondition
115115
assert isinstance(key, int) and isinstance(content, str)
@@ -130,12 +130,12 @@ def decrypt_string(self, content, key=0):
130130

131131
def encrypt_file(self, file, key=0):
132132
"""
133-
input: filename (str) and a key (int)
134-
output: returns true if encrypt process was
135-
successful otherwise false
136-
if key not passed the method uses the key by the constructor.
137-
otherwise key = 1
138-
"""
133+
input: filename (str) and a key (int)
134+
output: returns true if encrypt process was
135+
successful otherwise false
136+
if key not passed the method uses the key by the constructor.
137+
otherwise key = 1
138+
"""
139139

140140
# precondition
141141
assert isinstance(file, str) and isinstance(key, int)
@@ -155,12 +155,12 @@ def encrypt_file(self, file, key=0):
155155

156156
def decrypt_file(self, file, key):
157157
"""
158-
input: filename (str) and a key (int)
159-
output: returns true if decrypt process was
160-
successful otherwise false
161-
if key not passed the method uses the key by the constructor.
162-
otherwise key = 1
163-
"""
158+
input: filename (str) and a key (int)
159+
output: returns true if decrypt process was
160+
successful otherwise false
161+
if key not passed the method uses the key by the constructor.
162+
otherwise key = 1
163+
"""
164164

165165
# precondition
166166
assert isinstance(file, str) and isinstance(key, int)

conversions/decimal_to_binary.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44
def decimal_to_binary(num):
55

66
"""
7-
Convert a Integer Decimal Number to a Binary Number as str.
8-
>>> decimal_to_binary(0)
9-
'0b0'
10-
>>> decimal_to_binary(2)
11-
'0b10'
12-
>>> decimal_to_binary(7)
13-
'0b111'
14-
>>> decimal_to_binary(35)
15-
'0b100011'
16-
>>> # negatives work too
17-
>>> decimal_to_binary(-2)
18-
'-0b10'
19-
>>> # other floats will error
20-
>>> decimal_to_binary(16.16) # doctest: +ELLIPSIS
21-
Traceback (most recent call last):
22-
...
23-
TypeError: 'float' object cannot be interpreted as an integer
24-
>>> # strings will error as well
25-
>>> decimal_to_binary('0xfffff') # doctest: +ELLIPSIS
26-
Traceback (most recent call last):
27-
...
28-
TypeError: 'str' object cannot be interpreted as an integer
7+
Convert a Integer Decimal Number to a Binary Number as str.
8+
>>> decimal_to_binary(0)
9+
'0b0'
10+
>>> decimal_to_binary(2)
11+
'0b10'
12+
>>> decimal_to_binary(7)
13+
'0b111'
14+
>>> decimal_to_binary(35)
15+
'0b100011'
16+
>>> # negatives work too
17+
>>> decimal_to_binary(-2)
18+
'-0b10'
19+
>>> # other floats will error
20+
>>> decimal_to_binary(16.16) # doctest: +ELLIPSIS
21+
Traceback (most recent call last):
22+
...
23+
TypeError: 'float' object cannot be interpreted as an integer
24+
>>> # strings will error as well
25+
>>> decimal_to_binary('0xfffff') # doctest: +ELLIPSIS
26+
Traceback (most recent call last):
27+
...
28+
TypeError: 'str' object cannot be interpreted as an integer
2929
"""
3030

3131
if type(num) == float:

conversions/decimal_to_hexadecimal.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,38 @@
2323

2424
def decimal_to_hexadecimal(decimal):
2525
"""
26-
take integer decimal value, return hexadecimal representation as str beginning with 0x
27-
>>> decimal_to_hexadecimal(5)
28-
'0x5'
29-
>>> decimal_to_hexadecimal(15)
30-
'0xf'
31-
>>> decimal_to_hexadecimal(37)
32-
'0x25'
33-
>>> decimal_to_hexadecimal(255)
34-
'0xff'
35-
>>> decimal_to_hexadecimal(4096)
36-
'0x1000'
37-
>>> decimal_to_hexadecimal(999098)
38-
'0xf3eba'
39-
>>> # negatives work too
40-
>>> decimal_to_hexadecimal(-256)
41-
'-0x100'
42-
>>> # floats are acceptable if equivalent to an int
43-
>>> decimal_to_hexadecimal(17.0)
44-
'0x11'
45-
>>> # other floats will error
46-
>>> decimal_to_hexadecimal(16.16) # doctest: +ELLIPSIS
47-
Traceback (most recent call last):
48-
...
49-
AssertionError
50-
>>> # strings will error as well
51-
>>> decimal_to_hexadecimal('0xfffff') # doctest: +ELLIPSIS
52-
Traceback (most recent call last):
53-
...
54-
AssertionError
55-
>>> # results are the same when compared to Python's default hex function
56-
>>> decimal_to_hexadecimal(-256) == hex(-256)
57-
True
26+
take integer decimal value, return hexadecimal representation as str beginning with 0x
27+
>>> decimal_to_hexadecimal(5)
28+
'0x5'
29+
>>> decimal_to_hexadecimal(15)
30+
'0xf'
31+
>>> decimal_to_hexadecimal(37)
32+
'0x25'
33+
>>> decimal_to_hexadecimal(255)
34+
'0xff'
35+
>>> decimal_to_hexadecimal(4096)
36+
'0x1000'
37+
>>> decimal_to_hexadecimal(999098)
38+
'0xf3eba'
39+
>>> # negatives work too
40+
>>> decimal_to_hexadecimal(-256)
41+
'-0x100'
42+
>>> # floats are acceptable if equivalent to an int
43+
>>> decimal_to_hexadecimal(17.0)
44+
'0x11'
45+
>>> # other floats will error
46+
>>> decimal_to_hexadecimal(16.16) # doctest: +ELLIPSIS
47+
Traceback (most recent call last):
48+
...
49+
AssertionError
50+
>>> # strings will error as well
51+
>>> decimal_to_hexadecimal('0xfffff') # doctest: +ELLIPSIS
52+
Traceback (most recent call last):
53+
...
54+
AssertionError
55+
>>> # results are the same when compared to Python's default hex function
56+
>>> decimal_to_hexadecimal(-256) == hex(-256)
57+
True
5858
"""
5959
assert type(decimal) in (int, float) and decimal == int(decimal)
6060
hexadecimal = ""

conversions/decimal_to_octal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def decimal_to_octal(num: int) -> str:
1010
"""Convert a Decimal Number to an Octal Number.
11-
11+
1212
>>> all(decimal_to_octal(i) == oct(i) for i in (0, 2, 8, 64, 65, 216, 255, 256, 512))
1313
True
1414
"""

data_structures/binary_tree/avl_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def leftrotation(node):
105105

106106
def rightrotation(node):
107107
"""
108-
a mirror symmetry rotation of the leftrotation
108+
a mirror symmetry rotation of the leftrotation
109109
"""
110110
print("right rotation node:", node.getdata())
111111
ret = node.getright()

data_structures/binary_tree/red_black_tree.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class RedBlackTree:
2020

2121
def __init__(self, label=None, color=0, parent=None, left=None, right=None):
2222
"""Initialize a new Red-Black Tree node with the given values:
23-
label: The value associated with this node
24-
color: 0 if black, 1 if red
25-
parent: The parent to this node
26-
left: This node's left child
27-
right: This node's right child
23+
label: The value associated with this node
24+
color: 0 if black, 1 if red
25+
parent: The parent to this node
26+
left: This node's left child
27+
right: This node's right child
2828
"""
2929
self.label = label
3030
self.parent = parent

0 commit comments

Comments
 (0)