Skip to content

Commit c493e9c

Browse files
committed
added shebangs
1 parent ee3ace5 commit c493e9c

File tree

8 files changed

+21
-10
lines changed

8 files changed

+21
-10
lines changed

p1.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/python
2+
13
#Find the sum of all the multiples of 3 or 5 below 1000.
24

35
sum = 0

p10.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/python
2+
13
#Find the sum of all primes below two million
24
#Answer: 142913828922
35

p2.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/python
2+
13
#Project Euler problem #2
24

35
#Find the sum of all even terms in the Fibonacci sequence that do not exceed four million

p3.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/python
2+
13
#Project Euler #3
24

35
#What is the largest prime factor of the number 600851475143?
@@ -8,15 +10,10 @@
810

911
import prime_tools
1012

11-
#Compare a brute force method vs a method that uses a sieve of Eratosthenes to
13+
#Compare a brute force method vs a method that uses a sieve of Eratosthenes
1214

1315
num = 600851475143
1416

15-
# def find_2_factors(num):
16-
# for d in range(2, int(math.sqrt(num))):
17-
# if num % d == 0:
18-
# return [num/d, d]
19-
2017
def brute_factor(num):
2118
prime_factors = []
2219
found_factors = [num]

p6.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/python
2+
13
# Find the difference between the sum of the squares of the first 100 natural
24
# numbers and the square of the sum
35

p7.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/python
2+
13
#Project Euler #7
24

35
#What's the 10001st prime number?

p8.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/python
2+
13
#Find the greatest product of five consecutive digits in the 100 digit number
24
n = str(7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450)
35
#Answer = 40824

prime_tools.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
#!/usr/bin/python
2+
13
#Collection of useful tools for working with prime numbers
24

35
import math
46

57
def sieve(n):
68
#creates a Sieve of Eratosthenes from 2 to n-1
79
#Sieve is a dictionary where True indicates prime and False indicates nonprime
8-
sieve = dict.fromkeys(range(2, n), True)
10+
sv = dict.fromkeys(range(2, n), True)
911
for num in range(2, int(math.sqrt(n))):
10-
if sieve[num]:
12+
if sv[num]:
1113
#print "checking multiples of %d" %(num)
1214
for i in range(2, n/num + 1):
1315
#print " %d is not prime, marking False" %(num * i)
14-
sieve[num * i] = False
15-
return sieve
16+
sv[num * i] = False
17+
return sv
1618

1719
def isprime(num):
1820
#Brute force check if a number is prime by checking divisibility

0 commit comments

Comments
 (0)