Cuboid route
Among the first 100 problems, this one is not easy.
Since my old code was lost, I rewrote it. It still took me three hours to get it work in a relatively efficient way. It takes less than 1ms for my optimized version to get the correct answer.
Update 10/05/2017, I found my previous code for this problem is not efficient because I did not choose the number range carefully and I need to set the maximum to be large enough to get a correct answer for n=1e11. It is a little bit tricky to find an appropriate limit for the pythagorean triangle numbers. There is still room to make improvement, but I will live with it since I have already passed the projecteuler+ tests for this problem.
Showing posts with label binary search. Show all posts
Showing posts with label binary search. Show all posts
Monday, April 1, 2013
Tuesday, March 19, 2013
project euler problem 040
Champernowne's constant
This number appeared at least 3 times in all 400 problems. This is the easiest one. Problem 305 is much more difficult than 40. I used binary search on this problem. Simple and fast. I remember that the first time I saw this problem, I solved it by hand. It is not difficult since the number of digits involved is so small.
Update: Binary search is still an overkill if we use a function to count the numbers of digits up to n. With some simple math, the problem can be further simplified. since the numbers with one digit is 9 and with two digits is 90, etc.
This number appeared at least 3 times in all 400 problems. This is the easiest one. Problem 305 is much more difficult than 40. I used binary search on this problem. Simple and fast. I remember that the first time I saw this problem, I solved it by hand. It is not difficult since the number of digits involved is so small.
Update: Binary search is still an overkill if we use a function to count the numbers of digits up to n. With some simple math, the problem can be further simplified. since the numbers with one digit is 9 and with two digits is 90, etc.
Subscribe to:
Posts (Atom)