Wednesday, 25 November 2015

Project Euler Problems 4-6 by Easter Joy Trocio

Project Euler Problems 4-6

 
 
 


   CODER:


 
Easter Joy Trocio
Data Scientist

 

Language Used:

 
 
Problem Sets:
 

Largest palindrome product

Problem 4

Published on Friday, 16th November 2001, 06:00 pm; Solved by 274960; Difficulty rating: 5%
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.


Smallest multiple

Problem 5

Published on Friday, 30th November 2001, 06:00 pm; Solved by 286811; Difficulty rating: 5%
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?


Sum square difference

Problem 6

Published on Friday, 14th December 2001, 06:00 pm; Solved by 288687; Difficulty rating: 5%
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.


CODES:


Problem 4

 

def ReverseNumber(n, partial=0):
if n == 0:
return partial
print ReverseNumber(n / 10),partial
return ReverseNumber(n / 10, partial * 10 + n % 10)
A=range(700,999)
B=range(700,999)
A.reverse()
B.reverse()
 
for i in A:
for j in B:
a=i*j
if a == ReverseNumber(a):
print a
break

Problem 5



 
# Python code to find the factors of a number
# define a function
def primes(n):
primfac = []
d = 2
while d*d <= n:
while (n % d) == 0:
primfac.append(d)
n //= d
d += 1
if n > 1:
 
primfac.append(n)
return primfac
 
def factor(n):
fact=[]
p=n/2+1
for i in range(2,p):
  if n%i==0:
fact.append(i)
return fact
F=[]
for i in range(2,11):
F.append(primes(i))
 
 
 
 

Problem 6



sum(i**2 for i in range(101))-sum(range(101))**2
 
 



-->

No comments:

Post a Comment