Zhaoyang Dai
22C:016:A06
ID: 00719596
2. Use your program from Problem 1 to find a Pythagorean triple (x, y, z) such that 1500
x 1700 and 1500 y 1700. Write down one such triple as the answer to this
problem.
Answer: Pythagorean triple: 1666 1680 2366.
4
#Programmer: Zhaoyang Dai
#Section: 22C:016:A06
#ID: 00719596
def collinearityTest(pointList):
n=len(pointList)
a=0
#a indicates the first position in pointList
b=1
#b indicates the first position in pointList
c=2
#c indicates the first position in pointL
#Programmer: Zhaoyang Dai
#Section: 22C:016:A06
#ID: 00719596
n=raw_input("Please type your text. Type an extra enter when you are done.") #input
the first sentence
letterList=[]
#to get the first letter of every word we input
L=[]
#the final list L
alpha
Dai Zhaoyang
22C:016:A06
ID: 00719596
1. The following is an incomplete table of the first twenty whole numbers in decimal
and their ternary equivalents. Your task is to complete this table.
Decimal
Ternary
10
101
11
102
12
110
13
111
14
112
15
120
16
121
Zhaoyang Dai
22C:016:A06
ID:00719596
1. Copy and save the Python program below in a file called slowListBuild.py.
(a) Run slowListBuild.py and report the amount of time (in seconds) that the program
took to complete.
Answer: The result is 120.556999922 se
Zhaoyang Dai
22C:016:A06
ID:00719596
3. Use the function manyFastRandomWalks defined above to find out the average length
of a random walk (averaged over 1000 simulations) for (i) n = 100; jump = 2, (ii) n =
200; jump = 5, and (iii) n = 500; jump = 10.
An
Zhaoyang Dai
22C:016:A06
ID: 00719596
1. Euclid's algorithm computes the GCD of two numbers. It is based on the principle
that the GCD of two numbers does not change when the smaller number is
subtracted from the larger number. For example, the GCD of 35
#Programmer: Zhaoyang Dai
#Section: 22C:016:A06
#ID: 00719596
def collinearityTest(pointList):
n=len(pointList)
a=0
#a indicates the first position in pointList
b=1
#b indicates the first position in pointList
c=2
#c indicates the first position in pointL