Skip to content

Commit

Permalink
add problem set answer 1
Browse files Browse the repository at this point in the history
  • Loading branch information
halida committed Aug 16, 2011
1 parent 9ce7c7f commit 0d33a09
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ps1a.py
@@ -0,0 +1,19 @@
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
module: ps1a
"""
def main():
primes = [2, 3]
i = 3
while len(primes) < 1000:
i += 2
for j in primes:
if i % j == 0:
break
else:
primes.append(i)
print primes[1000-1]

if __name__=="__main__":
main()
16 changes: 16 additions & 0 deletions ps1a_2.py
@@ -0,0 +1,16 @@
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
module: ps1a_2
"""
count = 2
v = 3

while count < 1000:
for i in range(2, v):
if v % i == 0:
break
else:
count += 1
v += 2
print v
32 changes: 32 additions & 0 deletions ps1b.py
@@ -0,0 +1,32 @@
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
module: ps1b
"""
from math import *

def process(n):
count = 2
v = 3
result = log(2) + log(3)

while count < n:
for i in range(2, v):
if v % i == 0:
break
else:
count += 1
result += log(v)
v += 1

print n, ": ", result
return n

x = range(11, 200)
y = [process(i)
for i in range(11, 200)]

import numpy as np
import matplotlib.pyplot as plt

plt.plot(x, y)

0 comments on commit 0d33a09

Please sign in to comment.