ladbrokes.com

Tag Archives: Algorithm

Project Euler Question 15

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

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 \lt1000 for which 1/d contains Read more [...]

Project Euler Question 14

Question: The following iterative sequence is defined for the set of positive integers: n \rightarrown/2 (n is even) n \rightarrow 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 \rightarrow 40 \rightarrow 20 \rightarrow10 \rightarrow 5 \rightarrow 16 \rightarrow 8 \rightarrow 4 \rightarrow 2 \rightarrow 1 It can be seen that this sequence (starting at 13 and finishing Read more [...]

Project Euler Question 29

Question: Consider all integer combinations of ab for 2 \leq a \leq 5 and 2 \leq b \leq 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 \leq a \leq 100 Read more [...]

Project Euler Question 31

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 x_{n} that satisfy below equation x_{1}*100+x_{2}*50+x_{3}*20+x_{4}*10+x_{5}*5+x_{6}*2+x_{7}*1=200 Algorithm Read more [...]

Python Solution for Project Euler(Problem 007 - 009 )

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 004 - 006)

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. Solution 906609 Python: , just setup a loop of combination of 2 3-digit numbers ,and test if product of them is a palindrome . def palindrome(): rlt = 0 for i in range (999, 99, -1): for j in range (999, 99, -1): prod = str(i * j); prod_rev Read more [...]

Python & R Solution for Project Euler(Problem 001 - 003)

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 [...]

A Discrete Probability Models in R

There is an interesting Example in real world (From <mathematical modeling 3th>,Ch07): An electronics manufacturer produces a variety of diodes. Quality control engineers attempt to insure that faulty diodes will be detected in the factory before they are shipped .  It is estimated that 0.3% of the diodes produced will be faulty .  It is possible to test each  diode individually.  It is also possible to place a number of diodes in series and test the entire group .  If this test fails Read more [...]

Find Equal Sum in Two Number Set

Accounting Nightmare In account book, it is really nightmare if you try to find out a even group of transactions within a larger group .(by even group, we mean sum of credit equals to sum of debit) It is exhausting to find out 15 Debit + 25 Debit equals to 30 Credit + 10 Credit in a large transactions scope. Thanks to latest development of Python(2.7 with itertools module) , it is easy to implement a algorithm to find all possible groups in two data set.   Abstraction Lets back to Read more [...]