Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit078f49b

Browse files
committed
Formatting and comments.
1 parentd659e7e commit078f49b

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
deflongest_increasing_subsequence(sequence):
3-
sequence_length=len(sequence)
4-
T= [1foriinrange(sequence_length)]
4+
"""
5+
Returns the length of the longest increasing non-contiguous sequence
6+
"""
7+
length=len(sequence)
8+
counts= [1for_inrange(length)]
9+
10+
foriinrange(1,length):
11+
forjinrange(0,i):
12+
ifsequence[j]<sequence[i]:
13+
counts[i]=max(counts[i],counts[j]+1)
514

6-
forindex_iinrange(1,sequence_length):
7-
forindex_jinrange(0,index_i):
8-
ifsequence[index_j]<sequence[index_i]:
9-
T[index_i]=max(T[index_i],T[index_j]+1)
15+
returnmax(counts)
1016

11-
returnmax(T)
1217

1318
if__name__=='__main__':
14-
sequence= [1,101,10,2,3,100,4]
15-
assert4==longest_increasing_subsequence(sequence)
19+
sequence= [1,101,10,2,3,100,4,6,2]
20+
assert5==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
defstrongly_connected_components(self):
182182
"""
183183
Compute the vertices in the strongly connected components
184-
:return list of lists, one for eachcomponents vertices:
184+
:return list of lists, one for eachcomponent'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
deftest_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
deftest_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
deftest_topological_sort():
@@ -329,10 +329,10 @@ def test_topological_sort():
329329
deftest_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
defmain():
@@ -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
importscipy
44
importmatplotlib.pyplotasplt
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
returnabs(hash%m)
9495

9596

96-
9797
defshow_distribution(buckets,title):
98-
9998
counts= {}
10099
forvinbuckets:
101100
ifvincounts.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)

[8]ページ先頭

©2009-2025 Movatter.jp