Skip to content

Commit 1072b69

Browse files
committed
Wrap lines that go beyond GiHub Editor
1 parent bcaa88b commit 1072b69

File tree

17 files changed

+150
-79
lines changed

17 files changed

+150
-79
lines changed

ciphers/rsa_cipher.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import sys, rsa_key_generator as rkg, os
1+
import os
2+
import sys
3+
4+
import rsa_key_generator as rkg
25

36
DEFAULT_BLOCK_SIZE = 128
47
BYTE_SIZE = 256
@@ -92,7 +95,9 @@ def encryptAndWriteToFile(
9295
keySize, n, e = readKeyFile(keyFilename)
9396
if keySize < blockSize * 8:
9497
sys.exit(
95-
"ERROR: Block size is %s bits and key size is %s bits. The RSA cipher requires the block size to be equal to or greater than the key size. Either decrease the block size or use different keys."
98+
"ERROR: Block size is %s bits and key size is %s bits. The RSA cipher "
99+
"requires the block size to be equal to or greater than the key size. "
100+
"Either decrease the block size or use different keys."
96101
% (blockSize * 8, keySize)
97102
)
98103

@@ -117,7 +122,9 @@ def readFromFileAndDecrypt(messageFilename, keyFilename):
117122

118123
if keySize < blockSize * 8:
119124
sys.exit(
120-
"ERROR: Block size is %s bits and key size is %s bits. The RSA cipher requires the block size to be equal to or greater than the key size. Did you specify the correct key file and encrypted file?"
125+
"ERROR: Block size is %s bits and key size is %s bits. The RSA cipher "
126+
"requires the block size to be equal to or greater than the key size. "
127+
"Did you specify the correct key file and encrypted file?"
121128
% (blockSize * 8, keySize)
122129
)
123130

ciphers/rsa_key_generator.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import random, sys, os
2-
import rabin_miller as rabinMiller, cryptomath_module as cryptoMath
1+
import os
2+
import random
3+
import sys
4+
5+
import cryptomath_module as cryptoMath
6+
import rabin_miller as rabinMiller
37

48

59
def main():
@@ -35,7 +39,8 @@ def makeKeyFiles(name, keySize):
3539
):
3640
print("\nWARNING:")
3741
print(
38-
'"%s_pubkey.txt" or "%s_privkey.txt" already exists. \nUse a different name or delete these files and re-run this program.'
42+
'"%s_pubkey.txt" or "%s_privkey.txt" already exists. \n'
43+
'Use a different name or delete these files and re-run this program.'
3944
% (name, name)
4045
)
4146
sys.exit()

data_structures/linked_list/doubly_linked_list.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""
2-
- A linked list is similar to an array, it holds values. However, links in a linked list do not have indexes.
2+
- A linked list is similar to an array, it holds values. However, links in a linked
3+
list do not have indexes.
34
- This is an example of a double ended, doubly linked list.
45
- Each link references the next link and the previous one.
5-
- A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer, together with next pointer and data which are there in singly linked list.
6-
- Advantages over SLL - IT can be traversed in both forward and backward direction.,Delete operation is more efficient"""
6+
- A Doubly Linked List (DLL) contains an extra pointer, typically called previous
7+
pointer, together with next pointer and data which are there in singly linked list.
8+
- Advantages over SLL - IT can be traversed in both forward and backward direction.,
9+
Delete operation is more efficient"""
710

811

912
class LinkedList: # making main class named linked list
@@ -13,7 +16,7 @@ def __init__(self):
1316

1417
def insertHead(self, x):
1518
newLink = Link(x) # Create a new link with a value attached to it
16-
if self.isEmpty() == True: # Set the first element added to be the tail
19+
if self.isEmpty(): # Set the first element added to be the tail
1720
self.tail = newLink
1821
else:
1922
self.head.previous = newLink # newLink <-- currenthead(head)
@@ -23,7 +26,9 @@ def insertHead(self, x):
2326
def deleteHead(self):
2427
temp = self.head
2528
self.head = self.head.next # oldHead <--> 2ndElement(head)
26-
self.head.previous = None # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed
29+
# oldHead --> 2ndElement(head) nothing pointing at it so the old head will be
30+
# removed
31+
self.head.previous = None
2732
if self.head is None:
2833
self.tail = None # if empty linked list
2934
return temp

divide_and_conquer/strassen_matrix_multiplication.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,19 @@ def matrix_subtraction(matrix_a: List, matrix_b: List):
3131

3232
def split_matrix(a: List,) -> Tuple[List, List, List, List]:
3333
"""
34-
Given an even length matrix, returns the top_left, top_right, bot_left, bot_right quadrant.
34+
Given an even length matrix, returns the top_left, top_right, bot_left, bot_right
35+
quadrant.
3536
3637
>>> split_matrix([[4,3,2,4],[2,3,1,1],[6,5,4,3],[8,4,1,6]])
3738
([[4, 3], [2, 3]], [[2, 4], [1, 1]], [[6, 5], [8, 4]], [[4, 3], [1, 6]])
38-
>>> split_matrix([[4,3,2,4,4,3,2,4],[2,3,1,1,2,3,1,1],[6,5,4,3,6,5,4,3],[8,4,1,6,8,4,1,6],[4,3,2,4,4,3,2,4],[2,3,1,1,2,3,1,1],[6,5,4,3,6,5,4,3],[8,4,1,6,8,4,1,6]])
39-
([[4, 3, 2, 4], [2, 3, 1, 1], [6, 5, 4, 3], [8, 4, 1, 6]], [[4, 3, 2, 4], [2, 3, 1, 1], [6, 5, 4, 3], [8, 4, 1, 6]], [[4, 3, 2, 4], [2, 3, 1, 1], [6, 5, 4, 3], [8, 4, 1, 6]], [[4, 3, 2, 4], [2, 3, 1, 1], [6, 5, 4, 3], [8, 4, 1, 6]])
39+
>>> split_matrix([
40+
... [4,3,2,4,4,3,2,4],[2,3,1,1,2,3,1,1],[6,5,4,3,6,5,4,3],[8,4,1,6,8,4,1,6],
41+
... [4,3,2,4,4,3,2,4],[2,3,1,1,2,3,1,1],[6,5,4,3,6,5,4,3],[8,4,1,6,8,4,1,6]
42+
... ]) doctest: +NORMALIZE_WHITESPACE
43+
([[4, 3, 2, 4], [2, 3, 1, 1], [6, 5, 4, 3], [8, 4, 1, 6]], [[4, 3, 2, 4],
44+
[2, 3, 1, 1], [6, 5, 4, 3], [8, 4, 1, 6]], [[4, 3, 2, 4], [2, 3, 1, 1],
45+
[6, 5, 4, 3], [8, 4, 1, 6]], [[4, 3, 2, 4], [2, 3, 1, 1], [6, 5, 4, 3],
46+
[8, 4, 1, 6]])
4047
"""
4148
if len(a) % 2 != 0 or len(a[0]) % 2 != 0:
4249
raise Exception("Odd matrices are not supported!")
@@ -66,8 +73,8 @@ def print_matrix(matrix: List) -> None:
6673

6774
def actual_strassen(matrix_a: List, matrix_b: List) -> List:
6875
"""
69-
Recursive function to calculate the product of two matrices, using the Strassen Algorithm.
70-
It only supports even length matrices.
76+
Recursive function to calculate the product of two matrices, using the Strassen
77+
Algorithm. It only supports even length matrices.
7178
"""
7279
if matrix_dimensions(matrix_a) == (2, 2):
7380
return default_matrix_multiplication(matrix_a, matrix_b)
@@ -106,7 +113,8 @@ def strassen(matrix1: List, matrix2: List) -> List:
106113
"""
107114
if matrix_dimensions(matrix1)[1] != matrix_dimensions(matrix2)[0]:
108115
raise Exception(
109-
f"Unable to multiply these matrices, please check the dimensions. \nMatrix A:{matrix1} \nMatrix B:{matrix2}"
116+
f"Unable to multiply these matrices, please check the dimensions. \n"
117+
f"Matrix A:{matrix1} \nMatrix B:{matrix2}"
110118
)
111119
dimension1 = matrix_dimensions(matrix1)
112120
dimension2 = matrix_dimensions(matrix2)
@@ -119,7 +127,8 @@ def strassen(matrix1: List, matrix2: List) -> List:
119127
new_matrix1 = matrix1
120128
new_matrix2 = matrix2
121129

122-
# Adding zeros to the matrices so that the arrays dimensions are the same and also power of 2
130+
# Adding zeros to the matrices so that the arrays dimensions are the same and also
131+
# power of 2
123132
for i in range(0, maxim):
124133
if i < dimension1[0]:
125134
for j in range(dimension1[1], maxim):

dynamic_programming/bitmask.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
Here Bitmasking and DP are used for solving this.
55
66
Question :-
7-
We have N tasks and M people. Each person in M can do only certain of these tasks. Also a person can do only one task and a task is performed only by one person.
7+
We have N tasks and M people. Each person in M can do only certain of these tasks. Also
8+
a person can do only one task and a task is performed only by one person.
89
Find the total no of ways in which the tasks can be distributed.
9-
10-
1110
"""
1211
from collections import defaultdict
1312

@@ -25,7 +24,8 @@ def __init__(self, task_performed, total):
2524

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

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

3131
def CountWaysUtil(self, mask, task_no):
@@ -45,15 +45,17 @@ def CountWaysUtil(self, mask, task_no):
4545
# Number of ways when we don't this task in the arrangement
4646
total_ways_util = self.CountWaysUtil(mask, task_no + 1)
4747

48-
# now assign the tasks one by one to all possible persons and recursively assign for the remaining tasks.
48+
# now assign the tasks one by one to all possible persons and recursively
49+
# assign for the remaining tasks.
4950
if task_no in self.task:
5051
for p in self.task[task_no]:
5152

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

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

5961
# save the value.
@@ -85,6 +87,7 @@ def countNoOfWays(self, task_performed):
8587
)
8688
"""
8789
For the particular example the tasks can be distributed as
88-
(1,2,3), (1,2,4), (1,5,3), (1,5,4), (3,1,4), (3,2,4), (3,5,4), (4,1,3), (4,2,3), (4,5,3)
90+
(1,2,3), (1,2,4), (1,5,3), (1,5,4), (3,1,4),
91+
(3,2,4), (3,5,4), (4,1,3), (4,2,3), (4,5,3)
8992
total 10
9093
"""

dynamic_programming/edit_distance.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
Author : Turfa Auliarachman
33
Date : October 12, 2016
44
5-
This is a pure Python implementation of Dynamic Programming solution to the edit distance problem.
5+
This is a pure Python implementation of Dynamic Programming solution to the edit
6+
distance problem.
67
78
The problem is :
8-
Given two strings A and B. Find the minimum number of operations to string B such that A = B. The permitted operations are removal, insertion, and substitution.
9+
Given two strings A and B. Find the minimum number of operations to string B such that
10+
A = B. The permitted operations are removal, insertion, and substitution.
911
"""
1012

1113

machine_learning/decision_tree.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ def mean_squared_error(self, labels, prediction):
2020
mean_squared_error:
2121
@param labels: a one dimensional numpy array
2222
@param prediction: a floating point value
23-
return value: mean_squared_error calculates the error if prediction is used to estimate the labels
23+
return value: mean_squared_error calculates the error if prediction is used to
24+
estimate the labels
2425
>>> tester = Decision_Tree()
2526
>>> test_labels = np.array([1,2,3,4,5,6,7,8,9,10])
2627
>>> test_prediction = np.float(6)
27-
>>> assert tester.mean_squared_error(test_labels, test_prediction) == Test_Decision_Tree.helper_mean_squared_error_test(test_labels, test_prediction)
28+
>>> tester.mean_squared_error(test_labels, test_prediction) == (
29+
... Test_Decision_Tree.helper_mean_squared_error_test(test_labels,
30+
... test_prediction))
2831
>>> test_labels = np.array([1,2,3])
2932
>>> test_prediction = np.float(2)
30-
>>> assert tester.mean_squared_error(test_labels, test_prediction) == Test_Decision_Tree.helper_mean_squared_error_test(test_labels, test_prediction)
31-
33+
>>> assert tester.mean_squared_error(test_labels, test_prediction) == (
34+
... Test_Decision_Tree.helper_mean_squared_error_test(test_labels,
35+
... test_prediction)
3236
"""
3337
if labels.ndim != 1:
3438
print("Error: Input labels must be one dimensional")
@@ -46,7 +50,8 @@ def train(self, X, y):
4650
"""
4751

4852
"""
49-
this section is to check that the inputs conform to our dimensionality constraints
53+
this section is to check that the inputs conform to our dimensionality
54+
constraints
5055
"""
5156
if X.ndim != 1:
5257
print("Error: Input data set must be one dimensional")
@@ -72,7 +77,8 @@ def train(self, X, y):
7277
"""
7378
loop over all possible splits for the decision tree. find the best split.
7479
if no split exists that is less than 2 * error for the entire array
75-
then the data set is not split and the average for the entire array is used as the predictor
80+
then the data set is not split and the average for the entire array is used as
81+
the predictor
7682
"""
7783
for i in range(len(X)):
7884
if len(X[:i]) < self.min_leaf_size:
@@ -136,7 +142,7 @@ def helper_mean_squared_error_test(labels, prediction):
136142
helper_mean_squared_error_test:
137143
@param labels: a one dimensional numpy array
138144
@param prediction: a floating point value
139-
return value: helper_mean_squared_error_test calculates the mean squared error
145+
return value: helper_mean_squared_error_test calculates the mean squared error
140146
"""
141147
squared_error_sum = np.float(0)
142148
for label in labels:
@@ -147,9 +153,10 @@ def helper_mean_squared_error_test(labels, prediction):
147153

148154
def main():
149155
"""
150-
In this demonstration we're generating a sample data set from the sin function in numpy.
151-
We then train a decision tree on the data set and use the decision tree to predict the
152-
label of 10 different test values. Then the mean squared error over this test is displayed.
156+
In this demonstration we're generating a sample data set from the sin function in
157+
numpy. We then train a decision tree on the data set and use the decision tree to
158+
predict the label of 10 different test values. Then the mean squared error over
159+
this test is displayed.
153160
"""
154161
X = np.arange(-1.0, 1.0, 0.005)
155162
y = np.sin(X)

machine_learning/logistic_regression.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#!/usr/bin/python
22

3-
## Logistic Regression from scratch
3+
# Logistic Regression from scratch
44

55
# In[62]:
66

77
# In[63]:
88

99
# importing all the required libraries
1010

11-
""" Implementing logistic regression for classification problem
12-
Helpful resources : 1.Coursera ML course 2.https://medium.com/@martinpella/logistic-regression-from-scratch-in-python-124c5636b8ac"""
11+
"""
12+
Implementing logistic regression for classification problem
13+
Helpful resources:
14+
Coursera ML course
15+
https://medium.com/@martinpella/logistic-regression-from-scratch-in-python-124c5636b8ac
16+
"""
1317

1418
import numpy as np
1519
import matplotlib.pyplot as plt
@@ -21,7 +25,8 @@
2125

2226
# In[67]:
2327

24-
# sigmoid function or logistic function is used as a hypothesis function in classification problems
28+
# sigmoid function or logistic function is used as a hypothesis function in
29+
# classification problems
2530

2631

2732
def sigmoid_function(z):

machine_learning/support_vector_machines.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from sklearn.model_selection import train_test_split
44
import doctest
55

6+
67
# different functions implementing different types of SVM's
78
def NuSVC(train_x, train_y):
89
svc_NuSVC = svm.NuSVC()
@@ -17,8 +18,11 @@ def Linearsvc(train_x, train_y):
1718

1819

1920
def SVC(train_x, train_y):
20-
# svm.SVC(C=1.0, kernel='rbf', degree=3, gamma=0.0, coef0=0.0, shrinking=True, probability=False,tol=0.001, cache_size=200, class_weight=None, verbose=False, max_iter=-1, random_state=None)
21-
# various parameters like "kernel","gamma","C" can effectively tuned for a given machine learning model.
21+
# svm.SVC(C=1.0, kernel='rbf', degree=3, gamma=0.0, coef0=0.0, shrinking=True,
22+
# probability=False,tol=0.001, cache_size=200, class_weight=None, verbose=False,
23+
# max_iter=-1, random_state=None)
24+
# various parameters like "kernel","gamma","C" can effectively tuned for a given
25+
# machine learning model.
2226
SVC = svm.SVC(gamma="auto")
2327
SVC.fit(train_x, train_y)
2428
return SVC
@@ -27,8 +31,8 @@ def SVC(train_x, train_y):
2731
def test(X_new):
2832
"""
2933
3 test cases to be passed
30-
an array containing the sepal length (cm), sepal width (cm),petal length (cm),petal width (cm)
31-
based on which the target name will be predicted
34+
an array containing the sepal length (cm), sepal width (cm), petal length (cm),
35+
petal width (cm) based on which the target name will be predicted
3236
>>> test([1,2,1,4])
3337
'virginica'
3438
>>> test([5, 2, 4, 1])

maths/pi_monte_carlo_estimation.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,24 @@ def random_unit_square(cls):
2323

2424
def estimate_pi(number_of_simulations: int) -> float:
2525
"""
26-
Generates an estimate of the mathematical constant PI (see https://en.wikipedia.org/wiki/Monte_Carlo_method#Overview).
26+
Generates an estimate of the mathematical constant PI.
27+
See https://en.wikipedia.org/wiki/Monte_Carlo_method#Overview
2728
28-
The estimate is generated by Monte Carlo simulations. Let U be uniformly drawn from the unit square [0, 1) x [0, 1). The probability that U lies in the unit circle is:
29+
The estimate is generated by Monte Carlo simulations. Let U be uniformly drawn from
30+
the unit square [0, 1) x [0, 1). The probability that U lies in the unit circle is:
2931
3032
P[U in unit circle] = 1/4 PI
3133
3234
and therefore
3335
3436
PI = 4 * P[U in unit circle]
3537
36-
We can get an estimate of the probability P[U in unit circle] (see https://en.wikipedia.org/wiki/Empirical_probability) by:
38+
We can get an estimate of the probability P[U in unit circle].
39+
See https://en.wikipedia.org/wiki/Empirical_probability by:
3740
3841
1. Draw a point uniformly from the unit square.
39-
2. Repeat the first step n times and count the number of points in the unit circle, which is called m.
42+
2. Repeat the first step n times and count the number of points in the unit
43+
circle, which is called m.
4044
3. An estimate of P[U in unit circle] is m/n
4145
"""
4246
if number_of_simulations < 1:

maths/zellers_congruence.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def zeller(date_input: str) -> str:
147147

148148
doctest.testmod()
149149
parser = argparse.ArgumentParser(
150-
description="Find out what day of the week nearly any date is or was. Enter date as a string in the mm-dd-yyyy or mm/dd/yyyy format"
150+
description=("Find out what day of the week nearly any date is or was. Enter "
151+
"date as a string in the mm-dd-yyyy or mm/dd/yyyy format")
151152
)
152153
parser.add_argument(
153154
"date_input", type=str, help="Date as a string (mm-dd-yyyy or mm/dd/yyyy)"

0 commit comments

Comments
 (0)