440,036 Members | 1,963 Online
Need help? Post your question and get tips & solutions from a community of 440,036 IT Pros & Developers. It's quick & easy.

# 6 Pick Bet Grouping

 P: n/a (I apologise in advance for posting something slightly OT, but plead in mitigation that I'm trying to re-write an old, suboptimal VB6 (erk) brute-force attack in a shiny, elegant, pythonic manner. I would really appreciate some ideas about an appropriate algorithmic approach to this + pointers to any relevant implementations in Python. Along the way, I'm also trying to get Python into my organisation through the back door - so a further plea for tolerance in posting this here! :)) A single 6 Pick bet looks like this: RACE1 RACE2 RACE3 RACE4 RACE5 RACE6 runner1 / runner 2 / runner 3 / runner4 / runner5 / runner6 - \$amount e.g. we might have: 5 / 3 / 11 / 7 / 1 / 9 - \$50 (5 to come 1st or 2nd in Race1, 3 to come first or 2nd in Race 2, etc.) 7 / 3 / 11 / 7 / 1 / 9 - \$50 5 / 3 / 11 / 14 / 1 / 9 - \$50 7 / 3 / 11 / 14 / 1 / 9 - \$50 The totalizator system allows us to merge or group these four bets as follows: 5 + 7 / 3 / 11 / 7 + 14 / 1 / 9 - \$50 (\$200 total) This method of expressing multiple bets in one line is advantageous because we may have many thousands of combinations we wish to bet and only a limited amount of time in which to bet them. There are up to 14 horses in each race, so 7,529,536 possible 6 Pick bets. In practice, one might wish to bet (say)15,000 combinations out of these 7.5 million. However, it would be very nice to be able to *optimally* merge (as shown above) these 15,000 combinations so that they might fit on (say) 2,000 betting tickets instead of trying to write out 15,000 single tickets. To keep things simple, let's assume that all single bets are for the same amount. (In practice, however, this is not so.) Now, it's certainly possible to go about this via brute force iteration, but I would really appreciate it if anyone with a CS background could point me toward a smarter plan of attack. I have perused Skiena's Algorithm Handbook and various websites and can't seem to find an analogous problem. I'm hoping this is just my ignorance and that my brief exposition rings a bell for someone here. Nov 29 '06 #1
6 Replies

 P: n/a bullockbefriending bard wrote: (I apologise in advance for posting something slightly OT, but plead in mitigation that I'm trying to re-write an old, suboptimal VB6 (erk) brute-force attack in a shiny, elegant, pythonic manner. I would really appreciate some ideas about an appropriate algorithmic approach to this + pointers to any relevant implementations in Python. Along the way, I'm also trying to get Python into my organisation through the back door - so a further plea for tolerance in posting this here! :)) A single 6 Pick bet looks like this: RACE1 RACE2 RACE3 RACE4 RACE5 RACE6 runner1 / runner 2 / runner 3 / runner4 / runner5 / runner6 - \$amount e.g. we might have: 5 / 3 / 11 / 7 / 1 / 9 - \$50 (5 to come 1st or 2nd in Race1, 3 to come first or 2nd in Race 2, etc.) 7 / 3 / 11 / 7 / 1 / 9 - \$50 5 / 3 / 11 / 14 / 1 / 9 - \$50 7 / 3 / 11 / 14 / 1 / 9 - \$50 The totalizator system allows us to merge or group these four bets as follows: 5 + 7 / 3 / 11 / 7 + 14 / 1 / 9 - \$50 (\$200 total) This method of expressing multiple bets in one line is advantageous because we may have many thousands of combinations we wish to bet and only a limited amount of time in which to bet them. There are up to 14 horses in each race, so 7,529,536 possible 6 Pick bets. In practice, one might wish to bet (say)15,000 combinations out of these 7.5 million. However, it would be very nice to be able to *optimally* merge (as shown above) these 15,000 combinations so that they might fit on (say) 2,000 betting tickets instead of trying to write out 15,000 single tickets. To keep things simple, let's assume that all single bets are for the same amount. (In practice, however, this is not so.) Now, it's certainly possible to go about this via brute force iteration, but I would really appreciate it if anyone with a CS background could point me toward a smarter plan of attack. I have perused Skiena's Algorithm Handbook and various websites and can't seem to find an analogous problem. I'm hoping this is just my ignorance and that my brief exposition rings a bell for someone here. I don't understand exactly. Why not merge all your bets into a single line? What constraints exist on how many bets you can put onto one ticket? Do you meant you have some bag full of incoming bets, which you are re-lodging after some merging process? Does this mean you will have one ticket for each amount? Cheers, -T Nov 29 '06 #2

 P: n/a bullockbefriending bard wrote: e.g. we might have: 5 / 3 / 11 / 7 / 1 / 9 - \$50 (5 to come 1st or 2nd in Race1, 3 to come first or 2nd in Race 2, etc.) 7 / 3 / 11 / 7 / 1 / 9 - \$50 5 / 3 / 11 / 14 / 1 / 9 - \$50 7 / 3 / 11 / 14 / 1 / 9 - \$50 The totalizator system allows us to merge or group these four bets as follows: 5 + 7 / 3 / 11 / 7 + 14 / 1 / 9 - \$50 (\$200 total) It is unclear to me how you go from the four lines to the one, (or vice-versa)? Could you expand the explanation? - paddy. Nov 29 '06 #3

 P: n/a It seems straightforward: 1 / X / X ... and 4 / X / X ... becomes 1 + 4 / X / X If there were a 6 / X / X it would become 1 + 4 + 6 / X / X I think this means that all possible combinations for any particular amount may be grouped together in a single ticket. Cheers, -T Nov 29 '06 #4

 P: n/a Your explanation is correct. It's important to realise that effectively the input many thousands of single bets come out of a black box and it is then necessary for me to merge them into the grouped format to make things more manageable. Given an arbitrary bucket of single bets, it is by no means obvious how they should be grouped without doing something algorithmic. In grouping, it is also important to not inadvertently introduce any new single bets. For the purpose of this discussion, I am also assuming that all bets are the same size. That's not the case, but can leave that little twist for another day. Nov 29 '06 #5

 P: n/a Sorry, I perhaps didn't frame my initial post very well. I hope my reply to your other post below has answered these questions. Nov 29 '06 #6

 P: n/a The totalizator system allows us to merge or group these four bets as follows: 5 + 7 / 3 / 11 / 7 + 14 / 1 / 9 - \$50 (\$200 total) I'm still trying to get my head around what you're trying to do, but here's some code: ---------------snip----------------- data = ["5 / 3 / 11 / 7 / 1 / 9 - \$50", "7 / 3 / 11 / 7 / 1 / 9 - \$50", "5 / 3 / 11 / 14 / 1 / 9 - \$50", "7 / 3 / 11 / 14 / 1 / 9 - \$50"] pick6 = [{},{},{},{},{},{}] for line in data: amount = int(line.split("-")[1].strip().lstrip("\$")) runners = [int(s) for s in line.split("-")[0].split("/")] for x,r in enumerate(runners): qty,amt = pick6[x].get(r,(0,0)) qty += 1 amt += amount pick6[x][r] = (qty,amt) for place in range(6): print "For position ",place for runner in sorted(pick6[place].keys()): bets = pick6[place][runner][0] betamt = pick6[place][runner][1] print " Runner",runner,"has",bets,"bets for \$",betamt ---------------snip----------------- Output: For position 0 Runner 5 has 2 bets for \$ 100 Runner 7 has 2 bets for \$ 100 For position 1 Runner 3 has 4 bets for \$ 200 For position 2 Runner 11 has 4 bets for \$ 200 For position 3 Runner 7 has 2 bets for \$ 100 Runner 14 has 2 bets for \$ 100 For position 4 Runner 1 has 4 bets for \$ 200 For position 5 Runner 9 has 4 bets for \$ 200 Is that anywhere close? Nov 29 '06 #7

### This discussion thread is closed

Replies have been disabled for this discussion.