Wednesday, 25 November 2015

Project Euler Problems 1-3 by Easter Joy Trocio

 

"If there is no struggle, there is no progress."

Coder:

Easter Joy Trocio

Data Scientist

 
Background: Mathematics
Programming Languages used: Python, R, C, SQL, Tableau

The codes are written in :
 



Problem Statements:

         

Multiples of 3 and 5

Problem 1

Published on Friday, 5th October 2001, 06:00 pm; Solved by 515434; Difficulty rating: 5%
 
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.

Even Fibonacci numbers

Problem 2

Published on Friday, 19th October 2001, 06:00 pm; Solved by 421228; Difficulty rating: 5%
 
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.


Largest prime factor

Problem 3

Published on Friday, 2nd November 2001, 06:00 pm; Solved by 305098; Difficulty rating: 5%
 
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'''Problem Number 1'''

l=[]

for i in range(1000):
    if i%3== 0 or i%5==0:
        l.append(i)



b=list(set(l))

print sum(b)


'''Problem Number 2''' 



f=[1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
#Create a list of Fibonacci sequence until 4000000
while f[len(f)-1]< 4000000:
    n=f[len(f)-2]+f[len(f)-1]
    f.append(n)

f.pop(len(f)-1)

#Check if even
A=[] 
for i in f:
    if i%2==0:             
        A.append(i)
sum(A)

'''Problem Number 3''' 

#Check if a number is a factor of 600851475143 
fact= []
n= 600851475143
p= int(sqrt(n))+1

for i in range(2,p):
    if n%i==0:
        fact.append(i)  

#IsPrime
def isPrime(n):
    if type(n)==float:
        return 'NA'
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return 0
    return 1
fact.reverse()
for i in fact:   
    if isPrime(i)==1:
        print i
        break






















No comments:

Post a Comment