Thursday, March 27, 2014

project euler problem 458

Permutations of Project

I do not remember when I solved 3 PE problems in just one day. But it was definitely a long time ago. Just on March 24,  I solved 3 relatively easy PE problems in one day! 

I read the problem for 5 minutes or so before I fully I understood the problem. I was in the mood that I should use 26 letters! But after that the problem is simple and straight forward. The technique was used at least 3 times in previous problems, for example, problem 237, one of my favorite problems. After I set up everything correct, the first shot gave the correct answer.  Do not be misled by 7^7-7!(when did you see PE problem makers tell you how to solve the problem?), if you want to try it in a combinatoric way, you would struggle with the problem in a hard way.

project euler problem 461

Almost Pi

This problem is an easy problem if one plays with PE for some time. It uses the same algorithm as problem 266.

The algorithm is very fascinating! I really love the algorithm because I had a very painful time when I tried to solve problem 266. But this time, everything is easy! I wrote the code for 15 minutes or so and my first trial is the correct one.

project euler problem 463

A weird recurrence relation  

 I did not solve any PE problems recently because my work kept me very busy and I read some books recently such as Richard Stanley's famous book  Enumerative Combinatorics. It is an excellent book, but it takes a lot of time, the problems at the end of each chapter are very challenging!

 Just a couple days ago, I took a look at recent PE problems and found some of the problems are quite simple, for example, problem 463. 

This problem is not interesting at all. The recurrent equations looks difficult to human beings, but it is trivial for computers. After half an hour's coding and a few minutes debugging, the problem is solved! 

Friday, September 20, 2013

project euler problem 350

Constraining the least greatest and the greatest least

This problem is a relatively easy one. We are given some numbers like 1e6, 1e12 and 1e18.  1e18 ruled out the possibility of any sort of brute force. 1e12 means that we need to do some optimization on the numbers from 1e6 to 1e12 since it is still a burden for computer. Well, 1e6 is not so big a number, we can do whatever we like.

After sometime's thought, I found that there is a neat formula for this problem(it is not difficult to derive the formula). With this formula, it is very easy to find the number of valid lists for certain gcd and lcm.(Well, after I read the discussion, I found that this formula may be derived after a moment's thought!) My code first ran for 5 seconds, then I did some optimization since 1e18 is too large in some sense, then the code runs for 0.18 second.

Sunday, September 8, 2013

project euler problem 265

Binary Circles

This is a very simple problem. A simple recursive function can get the correct answer. It only needs 50 ms to get the correct answer. 

project euler problem 435

Polynomials of Fibonacci numbers

This problem is relatively simple. But a little bit math is required to avoid computer to do huge amount of work. This problem is very similar to some older problem. You may first  ask yourself a simpler question, how to calculate the 10^15th Fibonacci number(mod n)? 

 After I get the answer for F_7(11) correct. I immediately get the correct solution for the problem. The only bad thing is that I used some sort of bigInteger in my code, but it may not be necessary if you handle the problem in a different approach.

Saturday, September 7, 2013

project euler problem 266

Pseudo Square Root

This problem is not easy in my opinion. I forgot how I solved the problem for the first time.  But I remembered that it was slow. I then read the discussion and found a clever solution for this problem. I was surprised that many people knew the algorithm or found the algorithm by themselves. 

The algorithm can be used to solve problem 185 or problem 418 and now problem 461