File tree Expand file tree Collapse file tree 4 files changed +41
-0
lines changed
projects/collatz_conjecture Expand file tree Collapse file tree 4 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Collatz Conjecture
2
+
3
+ Reference [ Wikipedia] ( https://en.wikipedia.org/wiki/Collatz_conjecture )
Original file line number Diff line number Diff line change
1
+ import matplotlib .pyplot as plt
2
+
3
+ def n (num : int ) -> list :
4
+ _n = [num ]
5
+ # print(num)
6
+ while num > 1 :
7
+ if num % 2 :
8
+ # num is odd
9
+ num = num * 3 + 1
10
+ else :
11
+ # num is even
12
+ num = int (num / 2 )
13
+ _n .append (num )
14
+ return _n
15
+
16
+ if __name__ == "__main__" :
17
+ y = []
18
+ p = plt
19
+ for x in range (3 ,40 ):
20
+ z = n (x )
21
+ if max (z ) > 1 :
22
+ y .append (z )
23
+ p .plot (z )
24
+ print (x )
25
+
26
+ p .ylabel ('some numbers' )
27
+ p .show ()
Original file line number Diff line number Diff line change
1
+ matplotlib == 3.7.1
Original file line number Diff line number Diff line change
1
+ contourpy == 1.0.7
2
+ cycler == 0.11.0
3
+ fonttools == 4.39.3
4
+ kiwisolver == 1.4.4
1
5
markdown-it-py == 2.2.0
6
+ matplotlib == 3.7.1
2
7
mdurl == 0.1.2
3
8
numpy == 1.24.2
9
+ packaging == 23.0
10
+ Pillow == 9.4.0
4
11
Pygments == 2.14.0
12
+ pyparsing == 3.0.9
13
+ python-dateutil == 2.8.2
5
14
rich == 13.3.3
15
+ six == 1.16.0
6
16
tqdm == 4.65.0
You can’t perform that action at this time.
0 commit comments