Skip to content

Commit

Permalink
contribution guidelines checks (TheAlgorithms#1787)
Browse files Browse the repository at this point in the history
* spelling corrections

* review

* improved documentation, removed redundant variables, added testing

* added type hint

* camel case to snake case

* spelling fix

* review

* python --> Python # it is a brand name, not a snake

* explicit cast to int

* spaces in int list

* "!= None" to "is not None"

* Update comb_sort.py

* various spelling corrections in documentation & several variables naming conventions fix

* + char in file name

* import dependency - bug fix

Co-authored-by: John Law <[email protected]>
  • Loading branch information
matkosoric and poyea authored Mar 4, 2020
1 parent 2b19e84 commit 7f04e5c
Show file tree
Hide file tree
Showing 57 changed files with 198 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ wheels/
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# Usually these files are written by a Python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
Expand Down
2 changes: 1 addition & 1 deletion DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
* [Support Vector Machines](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/support_vector_machines.py)

## Maths
* [3N+1](https://github.com/TheAlgorithms/Python/blob/master/maths/3n+1.py)
* [3N+1](https://github.com/TheAlgorithms/Python/blob/master/maths/3n_plus_1.py)
* [Abs](https://github.com/TheAlgorithms/Python/blob/master/maths/abs.py)
* [Abs Max](https://github.com/TheAlgorithms/Python/blob/master/maths/abs_max.py)
* [Abs Min](https://github.com/TheAlgorithms/Python/blob/master/maths/abs_min.py)
Expand Down
4 changes: 2 additions & 2 deletions backtracking/n_queens.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def solve(board, row):
"""
It creates a state space tree and calls the safe function until it receives a
False Boolean and terminates that branch and backtracks to the next
poosible solution branch.
possible solution branch.
"""
if row >= len(board):
"""
Expand All @@ -56,7 +56,7 @@ def solve(board, row):
return
for i in range(len(board)):
"""
For every row it iterates through each column to check if it is feesible to place a
For every row it iterates through each column to check if it is feasible to place a
queen there.
If all the combinations for that particular branch are successful the board is
reinitialized for the next possible combination.
Expand Down
14 changes: 7 additions & 7 deletions ciphers/hill_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def __init__(self, encrypt_key):
encrypt_key is an NxN numpy matrix
"""
self.encrypt_key = self.modulus(encrypt_key) # mod36 calc's on the encrypt key
self.checkDeterminant() # validate the determinant of the encryption key
self.check_determinant() # validate the determinant of the encryption key
self.decrypt_key = None
self.break_key = encrypt_key.shape[0]

def checkDeterminant(self):
def check_determinant(self):
det = round(numpy.linalg.det(self.encrypt_key))

if det < 0:
Expand All @@ -83,7 +83,7 @@ def checkDeterminant(self):
)
)

def processText(self, text):
def process_text(self, text):
text = list(text.upper())
text = [char for char in text if char in self.key_string]

Expand All @@ -94,7 +94,7 @@ def processText(self, text):
return "".join(text)

def encrypt(self, text):
text = self.processText(text.upper())
text = self.process_text(text.upper())
encrypted = ""

for i in range(0, len(text) - self.break_key + 1, self.break_key):
Expand All @@ -109,7 +109,7 @@ def encrypt(self, text):

return encrypted

def makeDecryptKey(self):
def make_decrypt_key(self):
det = round(numpy.linalg.det(self.encrypt_key))

if det < 0:
Expand All @@ -129,8 +129,8 @@ def makeDecryptKey(self):
return self.toInt(self.modulus(inv_key))

def decrypt(self, text):
self.decrypt_key = self.makeDecryptKey()
text = self.processText(text.upper())
self.decrypt_key = self.make_decrypt_key()
text = self.process_text(text.upper())
decrypted = ""

for i in range(0, len(text) - self.break_key + 1, self.break_key):
Expand Down
4 changes: 2 additions & 2 deletions ciphers/onepad_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Onepad:
def encrypt(self, text):
"""Function to encrypt text using psedo-random numbers"""
"""Function to encrypt text using pseudo-random numbers"""
plain = [ord(i) for i in text]
key = []
cipher = []
Expand All @@ -15,7 +15,7 @@ def encrypt(self, text):
return cipher, key

def decrypt(self, cipher, key):
"""Function to decrypt text using psedo-random numbers."""
"""Function to decrypt text using pseudo-random numbers."""
plain = []
for i in range(len(key)):
p = int((cipher[i] - (key[i]) ** 2) / key[i])
Expand Down
36 changes: 18 additions & 18 deletions data_structures/binary_tree/binary_search_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ def __str__(self):
"""
return str(self.root)

def __reassign_nodes(self, node, newChildren):
if newChildren is not None: # reset its kids
newChildren.parent = node.parent
def __reassign_nodes(self, node, new_children):
if new_children is not None: # reset its kids
new_children.parent = node.parent
if node.parent is not None: # reset its parent
if self.is_right(node): # If it is the right children
node.parent.right = newChildren
node.parent.right = new_children
else:
node.parent.left = newChildren
node.parent.left = new_children
else:
self.root = newChildren
self.root = new_children

def is_right(self, node):
return node == node.parent.right
Expand Down Expand Up @@ -117,39 +117,39 @@ def remove(self, value):
elif node.right is None: # Has only left children
self.__reassign_nodes(node, node.left)
else:
tmpNode = self.get_max(
tmp_node = self.get_max(
node.left
) # Gets the max value of the left branch
self.remove(tmpNode.value)
) # Gets the max value of the left branch
self.remove(tmp_node.value)
node.value = (
tmpNode.value
) # Assigns the value to the node to delete and keesp tree structure
tmp_node.value
) # Assigns the value to the node to delete and keep tree structure

def preorder_traverse(self, node):
if node is not None:
yield node # Preorder Traversal
yield node # Preorder Traversal
yield from self.preorder_traverse(node.left)
yield from self.preorder_traverse(node.right)

def traversal_tree(self, traversalFunction=None):
def traversal_tree(self, traversal_function=None):
"""
This function traversal the tree.
You can pass a function to traversal the tree as needed by client code
"""
if traversalFunction is None:
if traversal_function is None:
return self.preorder_traverse(self.root)
else:
return traversalFunction(self.root)
return traversal_function(self.root)


def postorder(curr_node):
"""
postOrder (left, right, self)
"""
nodeList = list()
node_list = list()
if curr_node is not None:
nodeList = postorder(curr_node.left) + postorder(curr_node.right) + [curr_node]
return nodeList
node_list = postorder(curr_node.left) + postorder(curr_node.right) + [curr_node]
return node_list


def binary_search_tree():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def binary_tree_count(node_count: int) -> int:
"""
Return the number of possible of binary trees.
:param n: number of nodes
:return: Number of possilble binary trees
:return: Number of possible binary trees
>>> binary_tree_count(5)
5040
Expand Down
2 changes: 1 addition & 1 deletion data_structures/linked_list/deque_doubly.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, link_p, element, link_n):

def has_next_and_prev(self):
return " Prev -> {0}, Next -> {1}".format(
self._prev != None, self._next != None
self._prev is not None, self._next is not None
)

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion data_structures/linked_list/doubly_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def isEmpty(self): # Will return True if the list is empty

def display(self): # Prints contents of the list
current = self.head
while current != None:
while current is not None:
current.displayLink()
current = current.next
print()
Expand Down
2 changes: 1 addition & 1 deletion data_structures/queue/queue_on_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Queue represented by a python list"""
"""Queue represented by a Python list"""


class Queue:
Expand Down
2 changes: 1 addition & 1 deletion digital_image_processing/change_contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Changing contrast with PIL
This algorithm is used in
https://noivce.pythonanywhere.com/ python web app.
https://noivce.pythonanywhere.com/ Python web app.
python/black: True
flake8 : True
Expand Down
12 changes: 6 additions & 6 deletions divide_and_conquer/convex_hull.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,19 @@ def convex_hull_recursive(points):
right_most_point = points[n - 1]

convex_set = {left_most_point, right_most_point}
upperhull = []
lowerhull = []
upper_hull = []
lower_hull = []

for i in range(1, n - 1):
det = _det(left_most_point, right_most_point, points[i])

if det > 0:
upperhull.append(points[i])
upper_hull.append(points[i])
elif det < 0:
lowerhull.append(points[i])
lower_hull.append(points[i])

_construct_hull(upperhull, left_most_point, right_most_point, convex_set)
_construct_hull(lowerhull, right_most_point, left_most_point, convex_set)
_construct_hull(upper_hull, left_most_point, right_most_point, convex_set)
_construct_hull(lower_hull, right_most_point, left_most_point, convex_set)

return sorted(convex_set)

Expand Down
28 changes: 14 additions & 14 deletions dynamic_programming/bitmask.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
This is a python implementation for questions involving task assignments between people.
This is a Python implementation for questions involving task assignments between people.
Here Bitmasking and DP are used for solving this.
Question :-
Expand All @@ -25,41 +25,41 @@ def __init__(self, task_performed, total):

self.task = defaultdict(list) # stores the list of persons for each task

# finalmask is used to check if all persons are included by setting all bits to 1
self.finalmask = (1 << len(task_performed)) - 1
# final_mask is used to check if all persons are included by setting all bits to 1
self.final_mask = (1 << len(task_performed)) - 1

def CountWaysUtil(self, mask, taskno):
def CountWaysUtil(self, mask, task_no):

# if mask == self.finalmask all persons are distributed tasks, return 1
if mask == self.finalmask:
if mask == self.final_mask:
return 1

# if not everyone gets the task and no more tasks are available, return 0
if taskno > self.total_tasks:
if task_no > self.total_tasks:
return 0

# if case already considered
if self.dp[mask][taskno] != -1:
return self.dp[mask][taskno]
if self.dp[mask][task_no] != -1:
return self.dp[mask][task_no]

# Number of ways when we don't this task in the arrangement
total_ways_util = self.CountWaysUtil(mask, taskno + 1)
total_ways_util = self.CountWaysUtil(mask, task_no + 1)

# now assign the tasks one by one to all possible persons and recursively assign for the remaining tasks.
if taskno in self.task:
for p in self.task[taskno]:
if task_no in self.task:
for p in self.task[task_no]:

# if p is already given a task
if mask & (1 << p):
continue

# assign this task to p and change the mask value. And recursively assign tasks with the new mask value.
total_ways_util += self.CountWaysUtil(mask | (1 << p), taskno + 1)
total_ways_util += self.CountWaysUtil(mask | (1 << p), task_no + 1)

# save the value.
self.dp[mask][taskno] = total_ways_util
self.dp[mask][task_no] = total_ways_util

return self.dp[mask][taskno]
return self.dp[mask][task_no]

def countNoOfWays(self, task_performed):

Expand Down
2 changes: 1 addition & 1 deletion dynamic_programming/fibonacci.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get(self, sequence_no=None):
[0, 1, 1, 2, 3, 5]
[]
"""
if sequence_no != None:
if sequence_no is not None:
if sequence_no < len(self.fib_array):
return print(self.fib_array[: sequence_no + 1])
else:
Expand Down
2 changes: 1 addition & 1 deletion fuzzy_logic/fuzzy_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


if __name__ == "__main__":
# Create universe of discourse in python using linspace ()
# Create universe of discourse in Python using linspace ()
X = np.linspace(start=0, stop=75, num=75, endpoint=True, retstep=False)

# Create two fuzzy sets by defining any membership function (trapmf(), gbellmf(),gaussmf(), etc).
Expand Down
2 changes: 1 addition & 1 deletion graphs/bellman_ford.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def printDist(dist, V):


def BellmanFord(graph: List[Dict[str, int]], V: int, E: int, src: int) -> int:
r"""
"""
Returns shortest paths from a vertex src to all
other vertices.
"""
Expand Down
2 changes: 1 addition & 1 deletion graphs/directed_and_undirected_(weighted)_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import math as math
import time

# the dfault weight is 1 if not assigned but all the implementation is weighted
# the default weight is 1 if not assigned but all the implementation is weighted


class DirectedGraph:
Expand Down
Loading

0 comments on commit 7f04e5c

Please sign in to comment.