06年开始学perl，因为要用bioperl，08年开始用R，因为想要用bioconductor的包。刚学R的时候，一片混乱啊，矢量计算啥的，一开始很不习惯。

那时候知道Project Euler，通过用R写代码来解决这些数学问题，开始对R熟悉起来。这对我学习R和编程是很有帮助的。

一开始很多题目都是很简单的，直接进行暴力计算就行了，唯一的问题，可能是超出了R的计算精度，一开始把数拆成数组，后来发现GMP包之后，就变成简单起来。如果是用mathematica的话，这些都不成问题，如problem 48，mathematica可以直接算出来。

解这些题，有用cache缓存中间结果的，有使用递归的，有用动态规划的（动态规划是序列比对最常用的办法，当时还写了一段比对的程序）。

有些题，不知道其中的数学问题，解起来就比较麻烦，比如problem 15。

前面50题，除了Problem 26使用Octave完成，其它均使用R。用Octave，是在学Stanford的ML课程，课程使用Octave，所以拿来熟悉一下。不过实在不喜欢Octave/Matlab，课程学完，估计也就扔了。

最近发现mathematica很是牛X，估计以后会用mathematica来解题。

前天晚上肚子饿，没睡着，想到要写个总结文，于是昨天把前50题没解完的，都解了，剩下49题，今天解了，于是就有了此文。

1 Add all the natural numbers below one thousand that are multiples of 3 or 5.

2 By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

3 Find the largest prime factor of a composite number.

4 Find the largest palindrome made from the product of two 3-digit numbers.

5 What is the smallest number divisible by each of the numbers 1 to 20?

6 What is the difference between the sum of the squares and the square of the sums?

7 Find the 10001st prime.

8 Discover the largest product of five consecutive digits in the 1000-digit number.

9 Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000.

10 Calculate the sum of all the primes below two million.

11 What is the greatest product of four adjacent numbers on the same straight line in the 20 by 20 grid?

12 What is the value of the first triangle number to have over five hundred divisors?

13 Find the first ten digits of the sum of one-hundred 50-digit numbers.

14 Find the longest sequence using a starting number under one million.

15 Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?

16 What is the sum of the digits of the number 21000?

17 How many letters would be needed to write all the numbers in words from 1 to 1000?

18 Find the maximum sum travelling from the top of the triangle to the base.

19 How many Sundays fell on the first of the month during the twentieth century?

20 Find the sum of digits in 100!

21 Evaluate the sum of all amicable pairs under 10000.

22 What is the total of all the name scores in the file of first names?

23 Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.

24 What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?

25 What is the first term in the Fibonacci sequence to contain 1000 digits?

26 Find the value of d < 1000 for which 1/d contains the longest recurring cycle.

27 Find a quadratic formula that produces the maximum number of primes for consecutive values of n.

28 What is the sum of both diagonals in a 1001 by 1001 spiral?

29 How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?

30 Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

31 Investigating combinations of English currency denominations.

32 Find the sum of all numbers that can be written as pandigital products.

33 Discover all the fractions with an unorthodox cancelling method.

34 Find the sum of all numbers which are equal to the sum of the factorial of their digits.

35 How many circular primes are there below one million?

36 Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2.

37 Find the sum of all eleven primes that are both truncatable from left to right and right to left.

38 What is the largest 1 to 9 pandigital that can be formed by multiplying a fixed number by 1, 2, 3, ... ?

39 If p is the perimeter of a right angle triangle, {a, b, c}, which value, for p ≤ 1000, has the most solutions?

40 Finding the nth digit of the fractional part of the irrational number.

41 What is the largest n-digit pandigital prime that exists?

42 How many triangle words does the list of common English words contain?

43 Find the sum of all pandigital numbers with an unusual sub-string divisibility property.

44 Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

45 After 40755, what is the next triangle number that is also pentagonal and hexagonal?

46 What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

47 Find the first four consecutive integers to have four distinct primes factors.

48 Find the last ten digits of 1^1 + 2^2 + ... + 1000^1000.

49 Find arithmetic sequences, made of prime terms, whose four digits are permutations of each other.

50 Which prime, below one-million, can be written as the sum of the most consecutive primes?

刚去玩了一下，前面20题大都能在wolfram alpha里直接搜到，实在很爽

Reply

ygc Reply:

November 10th, 2011 at 10:41 am

http://code.google.com/p/projecteuler-solutions/

这里有专门收集答案的=,=

你用mathematica的啊？

Reply

azalea Reply:

November 10th, 2011 at 10:53 am

没啊，直接用题目搜基本就能搜到。

我也在用octave，挺好用的啊，那门ML课实在很水，写程序就是填空 = =

Reply

ygc Reply:

November 10th, 2011 at 10:55 am

写程序是很水，关键是思路嘛。

我准备全部都用R自己写。

我觉得那课程挺好的，比自己看书要好得多。

Reply

azalea Reply:

November 10th, 2011 at 11:02 am

恩 那个Ng童鞋真nice，不厌其烦，解释得很清楚，还一直安慰人说不懂部分微分没关系啦，我觉得是3门stanford公开课里最好的。

Reply

ygc Reply:

November 10th, 2011 at 11:55 am

据说CS 229数学讲得多点。

http://cs229.stanford.edu/materials.html

Reply

余老师，您以后publications能直接链接PDF不？

Reply

ygc Reply:

November 13th, 2011 at 6:53 pm

我觉得没人看，我有给链接的-,-

Reply

我把TCPL的练习丢github里了 ❓

Reply

我来膜拜下！

Reply

ygc Reply:

November 13th, 2011 at 6:55 pm

汗，前面题比较简单。

Reply