8000 Formatting and comments. · EntropyWorks/practice-python@078f49b · GitHub
[go: up one dir, main page]

Skip to content

Commit 078f49b

Browse files
committed
Formatting and comments.
1 parent d659e7e commit 078f49b

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11

2+
23
def longest_increasing_subsequence(sequence):
3-
sequence_length = len(sequence)
4-
T = [1 for i in range(sequence_length)]
4+
"""
5+
Returns the length of the longest increasing non-contiguous sequence
6+
"""
7+
length = len(sequence)
8+
counts = [1 for _ in range(length)]
9+
10+
for i in range(1, length):
11+
for j in range(0, i):
12+
if sequence[j] < sequence[i]:
13+
counts[i] = max(counts[i], counts[j] + 1)
514

6-
for index_i in range(1, sequence_length):
7-
for index_j in range(0, index_i):
8-
if sequence[index_j] < sequence[index_i]:
9-
T[index_i] = max(T[index_i], T[index_j] + 1)
15+
return max(counts)
1016

11-
return max(T)
1217

1318
if __name__ == '__main__':
14-
sequence = [1, 101, 10, 2, 3, 100, 4]
15-
assert 4 == longest_increasing_subsequence(sequence)
19+
sequence = [1, 101, 10, 2, 3, 100, 4, 6, 2]
20+
assert 5 == longest_increasing_subsequence(sequence)

graphs/directed_graph_list.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def topological_sort(self):
181181
def strongly_connected_components(self):
182182
"""
183183
Compute the vertices in the strongly connected components
184-
:return list of lists, one for each components vertices:
184+
:return list of lists, one for each component's vertices:
185185
"""
186186
stack = self.scc_dfs_forward_pass()
187187
components = self.scc_dfs_reverse_pass(stack)
@@ -310,14 +310,14 @@ def test_dfs():
310310
def test_bfs():
311311
dg1 = get_test_graph_1()
312312
p1 = dg1.bfs()
313-
assert(p1 == {1: 0, 2: 1, 4: 2, 5: 0, 6: 2, 8: 5})
313+
assert (p1 == {1: 0, 2: 1, 4: 2, 5: 0, 6: 2, 8: 5})
314314

315315

316316
def test_contains_cycle():
317-
assert(get_test_graph_1().contains_cycle() == False)
318-
assert(get_test_graph_2().contains_cycle() == False)
319-
assert(get_test_graph_3().contains_cycle() == False)
320-
assert(get_test_graph_4().contains_cycle() == True)
317+
assert (get_test_graph_1().contains_cycle() == False)
318+
assert (get_test_graph_2().contains_cycle() == False)
319+
assert (get_test_graph_3().contains_cycle() == False)
320+
assert (get_test_graph_4().contains_cycle() == True)
321321

322322

323323
def test_topological_sort():
@@ -329,10 +329,10 @@ def test_topological_sort():
329329
def test_strongly_connected_components():
330330
dg = get_test_graph_5()
331331

332-
assert(dg.contains_cycle())
332+
assert (dg.contains_cycle())
333333

334334
components = dg.strongly_connected_components()
335-
assert(components == [[10, 11, 9, 8], [7], [0], [1, 3, 2], [6, 4, 5]])
335+
assert (components == [[10, 11, 9, 8], [7], [0], [1, 3, 2], [6, 4, 5]])
336336

337337

338338
def main():
@@ -344,5 +344,6 @@ def main():
344344

345345
print("Tests complete.")
346346

347+
347348
if __name__ == "__main__":
348349
main()

hashes/hash-test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import scipy
44
import matplotlib.pyplot as plt
55

6+
67
# This script will test multiple hashes on strings to see if we get a uniform distribution
78

89

@@ -93,9 +94,7 @@ def polyhash_noprime(word, a, m):
9394
return abs(hash % m)
9495

9596

96-
9797
def show_distribution(buckets, title):
98-
9998
counts = {}
10099
for v in buckets:
101100
if v in counts.keys():
@@ -147,5 +146,6 @@ def main():
147146

148147
show_distribution(buckets, "Bucket size distribution - PolyHash, no prime")
149148

149+
150150
if __name__ == "__main__":
151151
main()
File renamed without changes.

0 commit comments

Comments
 (0)
0