Algorithm for condensing/consolidating number combinations -
using horse race betting scenario, have number of separate bets predicting first 4 finishers of race (superfecta).
the bets follows...
1/2/3/4 1/2/3/5 1/2/4/3 1/2/4/5 1/2/5/3 1/2/5/4 what want combine or condense these separate combinations as possible. bets above, can condensed 1 line...
1/2/3,4,5/3,4,5 but if removed last bet list: 1/2/5/4 ...
1/2/3/4 1/2/3/5 1/2/4/3 1/2/4/5 1/2/5/3 the condensed bets instead have 2 lines:
1/2/3,4/3,4,5 1/2/5/3 what algorithm this?
i find easiest think kind of thing pretty pictures. how try build graphs?
first example
1/2/3/4 1/2/3/5 1/2/4/3 1/2/4/5 1/2/5/3 1/2/5/4 ...could this, in graph form:
each path top bottom (e.g. 1->2->4->3) corresponds row in initial format.
if start graph, (perhaps) can run little algorithm on graph simplify in way you're looking for. here's we'll try:
- start @ top of graph, , move down level level. (the first level contains blue node
1.) - for each node in current level, count number of children. if there 1 child, skip node. (since blue node
1has 1 child, we'll skip green node2.) - for each of multiple children, construct set contains child , grandchildren. (the red node
3has set{3,4,5}, red4has set{3,4,5}, , red5has set{3,4,5}.) - if of these sets identical, replace associated children/grandchildren single node containing children, pointing grandchild contains set. (since 3 red nodes have identical sets, replaced.)

second example
1/2/3/4 1/2/3/5 1/2/4/3 1/2/4/5 1/2/5/3 ...could this, in graph form:

the red nodes 3 , 4 have identical sets (i.e. {3,4,5}), replaced. red node 5 doesn't have same set red nodes 3 , 4, leave alone.

as before, each path through simplified tree represents 1 row of output.
(i haven't covered happens if replace children/grandchildren when there great-grandchildren. should start @ bottom row , work way upwards.)
Comments
Post a Comment