Hint for Problem 15

A fairly interesting math problem from Project Euler.
Problem 15
By far, this path question is the only one I put some thought in it, other problems' answer are found in less than 5 minutes each.

Best idea when meeting problems like this is to change geometric objects into algebra objects.
so there is a function, f(x), which will produce the amount of paths for a x*x block.
f(1) = 2, I tried it by drawing it out
f(2) = 6, given
any patters? not really.
I don't want to get into programming to solve this problem because I can see this does not need brute force attack, it can be solved by a equation for f(x)
now, I have to introduce another function, g(x,y), where x is the width of the blocks and y is the length of the blocks. it's easy to see the special case for this function, when x=y, is f(x).
with a little reasoning, g(x,y) = g(y,x) can be deducted, because after a rotation, the shape is the same.
there are only 2 choices for the first step, either going toward the end point by following horizontal line or the vertical line. after that, the problem deduce to a (x-1)*y or a (y-1)*x block. A inspirational found, because following recurrence will save the day
g(x,y) = g(x-1,y) + g(x,y-1)
Find the explicit formula for this recurrence and you can solve for the answer.

There is an incredibly easy

There is an incredibly easy way to solve this problem using the combination function. I won't give it away, but its obvious once you think about it for a while. (hint: each route will have 20 moves sideways and 20 down, for a total combination of 40).

I wish I'm good with

Mgccl's picture

I wish I'm good with combinatorics. For some reason, I just don't really get it... >.<

The combinatorics answer is

The combinatorics answer is much simpler. For an n x m grid, the total combinations are

(n + m)! / n!m!

Using combinatorics

Cameron Zemek's picture

To see an explanation of why this is a combinations problem:
http://grom.zeminvaders.net/blog/project-euler-problem-15

Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar. If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <fn>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.

More information about formatting options

What is 20 + 9?
To combat spam, please solve the math question above.
Honey Pot that kill bots