• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Project Euler : problem 15

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm learning java with Head First Java,and having a go at projects Euler problems, learning algorithms as I go along....

I'm completely lost about how to tackle problem15. http://projecteuler.net/index.php?section=problems&id=15
is that a graph theory problem? should I use List or Matrices to represent the grid in an algorithm?

Any hints(just hints!) will be appreciated.

Thanks.


 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have try Euler problems before but not this one. Ultimately it's all math.

2x2 grid=6 routes
3x3 grid=? routes
...
20x20 grid=? routes

Once you figure out the pattern.... voila.
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One word... Recursion.
(Spoiler) Look at this.

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a simple problem , very simpel solution:

a 20x20 grid will be traversed in a lot of way. But each way is composed of 40 simple actions
_simple_action_DOWN: from current point move one step down (1 unit)
_simple_action_LEFT: from current point move one step left (1 unit)

So the question is equivalent to: given 40 indexes place 20 DOWN and 20 LEFT on them
Meaning given 40 indexex that are all DOWN , chose 20 random ones and palce LEFT on them. meaning Combinations of 40 taken by 20.


Same generalization for a rectangle of sizes L and l : given L+l position , choose randomly L of them = Combinations of (L+l) taken by l


Sorry for the English , not my native language.
 
Ryan McGuire
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, how about this variation:

How many ways are there to get from (0,0) to (20,20) (in the lower right quadrant, for the sake of discussion) if you're allowed to backtrack at most once? i.e. You're allowed one step to the left or one step up, but not both.

 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pascal's triangle is also appropriate here...
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:pascal's triangle is also appropriate here...


This is far and away the most helpful comment pertaining to this problem that I have yet seen. Thank you, thank you!
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FYI: Myke's post should have been the best post as the answer is simply 20C40. And yes a py tri will work, but why. You don't need it.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Fahlbusch wrote:FYI: Myke's post should have been the best post as the answer is simply 20C40. And yes a py tri will work, but why. You don't need it.


I was trying to give a hint without giving away the entire solution. Just saying "the answer is 'how can you choose 20 out of 40 elements'?" doesn't help the person understand WHY it is the answer.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic