Reply to topic  [ 12 posts ] 
Combinatorics 
Author Message
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
I keep seeing this mentioned all over Project Euler and wondered what it is?

Is it purely just calculating the nCr solution to a problem and then working out the answer to that solution?

Or is there something more involed?

For instance, I search on wiki and it starts mentioning binary trees and stuff. Anyone got any good links of where to look at this from the point of view of programming?

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Tue Aug 23, 2011 12:18 pm
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 6:44 pm
Posts: 4141
Location: Exeter
Reply with quote
Combinatorics is (from what I remember) the process of counting without counting.

nCr work in some circumstances (such as is seen on Euler) but it covers other bits as well. Factorials crop up a lot.

_________________
"The woman is a riddle inside a mystery wrapped in an enigma I've had sex with."


Tue Aug 23, 2011 12:31 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
OK, so if the question was ...

There are 10 counters numbered from 0 to 9. How many ways of picking 3 counters are there?

That would be an nCr using n = 10 and r = 3.

10C3 = 10! / 3!(10-3)!
= 10! / 3! x 7!
= 8 x 9 x 10 / 6
= 120

I can understand that and it's a fairly easy equation to come up with from basic principles.

According to the Project Euler forums there is a combinatorics solution to Problem 37...
[quote="Problem 37"]The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.

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

NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.[/quiote]
How would you work this back to combinatorics?

Even question 15 (routes through a 20x20 grid) is screaming out to me to be a combinatorics solution but I can't for the life of me work out how you would find the solution to it?

I think I need to go back and start learning this stuff again :D

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Tue Aug 23, 2011 12:42 pm
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 6:44 pm
Posts: 4141
Location: Exeter
Reply with quote
Realising there was a combinatorics route to solve 15 was how I did it. I haven't worked out a procedural method for getting the answer.

Hint:
It helps to realise that every route is the same length, and is always an equal split of right and down moves...

_________________
"The woman is a riddle inside a mystery wrapped in an enigma I've had sex with."


Tue Aug 23, 2011 12:46 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
jonlumb wrote:
Realising there was a combinatorics route to solve 15 was how I did it. I haven't worked out a procedural method for getting the answer.

Hint:
It helps to realise that every route is the same length, and is always an equal split of right and down moves...

Ah ok.
I kind of did it in a very basic shortest path algorithm but instead o counting the path length I counted the number of times I went to each point.

i.e. the number of routes to each point is just the sum of the number of routes to the point immediately above it and to the left of it.


...I just got your hint!

OK, starting to work it out.

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Last edited by Fogmeister on Tue Aug 23, 2011 1:10 pm, edited 1 time in total.



Tue Aug 23, 2011 12:56 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
OK, so I've worked out the grid one.

Each route in a 20x20 grid is made up of 40 steps. 20 of them are sideways and 20 are down.

The solution is then just a basic nCr of how many ways there are to choose 20 down stesp out of 40 total steps.

i.e. 40C20 = 137846528820

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Tue Aug 23, 2011 1:04 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
OK, so I get that but then why would you need a computer program to solve it?

Sorry if I seem like I'm being an idiot.

There is a question about lexicographic permutations of 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

I can kind of see how the combinatoric solution would go but then it removes the need for a computer program surely?

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Tue Aug 23, 2011 1:18 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Jun 18, 2009 5:10 pm
Posts: 5836
Reply with quote
Combinatrix

That so should be something else... :lol:

_________________
Jim

Image


Tue Aug 23, 2011 1:20 pm
Profile
What's a life?
User avatar

Joined: Thu Apr 23, 2009 7:26 pm
Posts: 17040
Reply with quote
rustybucket wrote:
Combinatrix
That so should be something else... :lol:

What, like a character in Asterix the Gaul?


Tue Aug 23, 2011 4:30 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Jun 18, 2009 5:10 pm
Posts: 5836
Reply with quote
jonbwfc wrote:
rustybucket wrote:
Combinatrix
That so should be something else... :lol:

What, like a character in Asterix the Gaul?

Dom.....

_________________
Jim

Image


Tue Aug 23, 2011 4:38 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:58 pm
Posts: 8767
Location: behind the sofa
Reply with quote
A leather clad hairdresser?

_________________
jonbwfc's law: "In any forum thread someone will, no matter what the subject, mention Firefly."

When you're feeling too silly for x404, youRwired.net


Tue Aug 23, 2011 4:57 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
Ah!

I figured out 24 using a combinatoric algorithm... although I did it in Excel.

Going to try to write a program to do the same thing.

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Wed Aug 24, 2011 11:50 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ] 

Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.