Link to home
Start Free TrialLog in
Avatar of alzzz
alzzz

asked on

Programmatically create all possible score combinations

Hi,

I'm writing a piece of code that for a given score (eg 2-1) must identify all the possible paths to this score (eg 0-1,1-1,2-1 and 1-0,1-1,2-1 and 1-0,2-0,2-1)

can anybody think of an algorithm that achieves this?

Also i will be coding this in java so if anybody has any tips there too it would be very appreciated.

Thanks in advance,
Alex
Avatar of Sean Stuber
Sean Stuber

Here's a simple (i.e not necessarily most efficient) way,  use graph theory,

first, build a graph of all possible scores  given final score A-B

loop x from 0 to A
     loop y from 0 to B
          add node x,y
     end loop
end loop

next, add connections from each node....
(note, for efficiency, some of these could be built as the nodes are added above)

loop m through node collection
      loop n through node collection
            // m(a,b) means node m with score a-b
            if m(a,b) = n(a+1,b) or if m(a,b) = n(a,b+1) then add connection from n to m
      end loop
end loop

use any graph traversing algorithm you want, you should be able to google up some written in java
Avatar of alzzz

ASKER

@sdstuber - regarding your solution, I think i understand what you are doing but if i want to save each combination as HAH  (Where H is Home Team scored and A is away scored), But as we go to higher scores the amount of combinations will increase - how do you recommend handling this?

@ozo - thats kind of what i want except i think it only shows the total amount of combinations?
i need to map every possible step!
I'm not sure what you're asking about the combinations.  Yes, the possible score combinations will increase dramatically as the scores increase but there is no "trick" for that.  You're looking for an exhaustive algorithm so you'll have lots of data, that's just the nature of the beast.
Avatar of alzzz

ASKER

ok thanks - ill give it a try and get back to you
ASKER CERTIFIED SOLUTION
Avatar of kalamarius
kalamarius
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alzzz

ASKER

thats looks very promising cheers - i have to run it for upto 136 different scores so this may limit its usability.