-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCollatz_Conjecture.py
More file actions
55 lines (45 loc) · 1.03 KB
/
Copy pathCollatz_Conjecture.py
File metadata and controls
55 lines (45 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#Import libraries
import turtle as T
#Number of iterations
Iterantions=50
#angle of conjecture drawing
angle = 10
#how far the turle will move
length = 25
#where the pen starts each line
x,y = 300,-300
#For adding
numSteady = 2
num = numSteady
#Setting up turtle
T.speed(0)
T.up()
T.goto(x, y)
T.setheading(90)
T.down()
T.colormode(255)
#making pretty colors
B = 0
BIncrease = round(255/Iterantions)
#while loop
while numSteady < Iterantions:
T.pencolor(0,-B+255,B)
#If num is divisible by 2 do this:
if (num % 2) == 0:
T.left(angle)
T.forward(length)
num = num/2
#If num is NOT equally divisible by 2 do this:
else:
T.right(angle)
T.forward(length)
num = num*3+1
#If num <= 1, reseat back to x and y axis, and continue the program
if num <= 1:
T.up()
T.goto(x, y)
T.setheading(90)
T.down()
numSteady = numSteady + 2
num = numSteady
B = B + BIncrease