Tag Archives: Project Euler
Project Euler Question 15
Posted by Shawn Zhang
on December 23, 2012
No comments
Question:
Starting in the top left corner of a 2*2 grid, there are 6 routes (without backtracking) to the bottom right corner.How many routes are there through a 20*20 grid?
Solution:
This is not a particular question for programming ,it seems like a more mathematics problem for me . for moving from top left to right down , only consist two direction "down/ right", all path is a combination of 20 down and 20 right moves, so ,solution is just number of combination 20 of 40 instruction on move .
For Read more [...]
Project Euler Problem 26
Posted by Shawn Zhang
on December 23, 2012
No comments
Question
A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:
1/2
=
0.5
1/3
=
0.(3)
1/4
=
0.25
1/5
=
0.2
1/6
=
0.1(6)
1/7
=
0.(142857)
1/8
=
0.125
1/9
=
0.(1)
1/10
=
0.1
Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.
Find the value of d
1000 for which 1/d contains Read more [...]
1000 for which 1/d contains Read more [...] Project Euler Question 14
Posted by Shawn Zhang
on December 20, 2012
No comments
Question:
The following iterative sequence is defined for the set of positive integers:
n
n/2 (n is even)
n
3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the following sequence:
13
40
20
10
5
16
8
4
2
1
It can be seen that this sequence (starting at 13 and finishing Read more [...]
n/2 (n is even)
n
3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the following sequence:
13
40
20
10
5
16
8
4
2
1
It can be seen that this sequence (starting at 13 and finishing Read more [...] Project Euler Question 29
Posted by Shawn Zhang
on December 19, 2012
No comments
Question:
Consider all integer combinations of ab for 2
a
5 and 2
b
5:
22=4, 23=8, 24=16, 25=32
32=9, 33=27, 34=81, 35=243
42=16, 43=64, 44=256, 45=1024
52=25, 53=125, 54=625, 55=3125
If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:
4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
How many distinct terms are in the sequence generated by ab for 2
a
100 Read more [...]
a
5 and 2
b
5:
22=4, 23=8, 24=16, 25=32
32=9, 33=27, 34=81, 35=243
42=16, 43=64, 44=256, 45=1024
52=25, 53=125, 54=625, 55=3125
If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:
4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
How many distinct terms are in the sequence generated by ab for 2
a
100 Read more [...] Project Euler Question 31
Posted by Shawn Zhang
on December 18, 2012
No comments
Question 31:
In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).x
It is possible to make £2 in the following way:
1X£1 + 1x50p + 2x20p + 1x5p + 1x2p + 3x1p
How many different ways can £2 be made using any number of coins?
Solution :
actually this is a linear algebra question : Find all possible
that satisfy below equation
Algorithm Read more [...]
that satisfy below equation
Algorithm Read more [...] Project Euler Problem 36,41
Posted by Shawn Zhang
on October 15, 2012
No comments
Problem 36:
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
(Please note that the palindromic number, in either base, may not include leading zeros.)
Key : to access if the binary is palindromic , most elegant way in Python is to check if the string of binary is same to the string after reversed . and another trick is that , In Python , " 333 and True" Read more [...]
Project Euler Problem 11 ,13
Posted by Shawn Zhang
on September 13, 2012
No comments
Problem 11
In the 20*20 grid below, four numbers along a diagonal line have been marked in red.
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 Read more [...]
Project Eular Question 020 - 021
Posted by Shawn Zhang
on March 24, 2012
No comments
Question 20
n! means n * (n - 1) * ... * 3 * 2 * 1
For example, 10! = 10 * 9 * ... * 3 * 2 * 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Find the sum of the digits in the number 100!
Solution :
sum([int(i) for i in list(str(reduce(lambda x,y:x *y,range(1,100))))])
Question 21
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
I've found that is really cool in Read more [...]
Python Solution for Project Euler(Problem 007 - 009 )
Posted by Shawn Zhang
on March 20, 2012
No comments
Question 007
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
Solution : 104743
Thanks to Prime_number_theorem(link: http://en.wikipedia.org/wiki/Prime_number_theorem ) There is approximate formula to figure the Nth number of prime number . The answer is actually programming language independent.
It must be a joke in J, I do serious considering learning J !
p: 10000
Question 8:
Find the Read more [...]
Python & R Solution for Project Euler(Problem 001 - 003)
Posted by Shawn Zhang
on March 17, 2012
No comments
1. 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.
Solution: 233168
Python, powerful range function generate list numbers via step
sum(range(0,1000,3)) + sum(range(0,1000,5)) - sum(range(0,1000,15))
R, we use seq() to generate this value list .
> sum(seq(from=0, to=999, by=3)) + sum(seq(from=0,to=999,by=5)) -sum(seq(from=0,to=999,by=15))
[1] 233168
2. Read more [...]