Skip to content

Commit 8278a96

Browse files
committed
adding collatz conjecture
1 parent 8928dab commit 8278a96

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Collatz Conjecture
2+
3+
Reference [Wikipedia](https://en.wikipedia.org/wiki/Collatz_conjecture)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
matplotlib==3.7.1

requirements.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
contourpy==1.0.7
2+
cycler==0.11.0
3+
fonttools==4.39.3
4+
kiwisolver==1.4.4
15
markdown-it-py==2.2.0
6+
matplotlib==3.7.1
27
mdurl==0.1.2
38
numpy==1.24.2
9+
packaging==23.0
10+
Pillow==9.4.0
411
Pygments==2.14.0
12+
pyparsing==3.0.9
13+
python-dateutil==2.8.2
514
rich==13.3.3
15+
six==1.16.0
616
tqdm==4.65.0

0 commit comments

Comments
 (0)