Enigmatic Code

Programming Enigma Puzzles

Enigma 125: A great day for the race

From New Scientist #1269, 3rd September 1981 [link]

Fred Betts noticed that there were nine runners in the big race and asked his bookie what odds he was offering.

“3-1 on Bonnie Lass, 4-1 on Golden Stirrup, 7-1 on Two’s a Crowd, 9-1 on Greek Hero and 39-1 the field,” he replied.

Fred thought for a few moments and then astounded the bookie by placing a bet on each of the nine horses, all to win. No each-way nonsense for fearless Fred. And all on credit, of course.

“You might as well give me my winnings now,” said Fred.

“The race hasn’t been run yet, sir,” smiled the bookie.

“That doesn’t matter,” said Fred. “When it has, you’ll owe me £200.”

And he was right.

How much did he stake on each horse?

[enigma125]

One response to “Enigma 125: A great day for the race

  1. Jim Randell 9 September 2013 at 9:45 am

    We derive a series of 5 equations in 5 variables (the stake for each of the odds). These can then be solved manually, or programatically.

    We can use SymPy to get exact answers in 306ms.

    from sympy import symbols, solve, Eq
    
    (a, b, c, d, e) = symbols('a b c d e')
    
    # total stake
    t = a + b + c + d + 5 * e
    
    # whichever horse wins, we want to end up with 200 pounds
    r = solve((
      Eq(4 * a - t, 200), # A: 3-1 Bonnie Lass 
      Eq(5 * b - t, 200), # B: 4-1 Golden Stirrup
      Eq(8 * c - t, 200), # C: 7-1 Two's A Crowd
      Eq(10 * d - t, 200), # D: 9-1 Greek Hero
      Eq(40 * e - t, 200), # E: 39-1 any of the others
    ))
    
    print(r)
    

    or, we can use a numerical solver like PyMathProg to get the answer in 35ms.

    import pymprog
    from enigma import printf
    
    p = pymprog.model('enigma125')
    
    (a, b, c, d, e) = (p.var(name=x) for x in 'abcde')
    
    p.st( 4 * a - (a + b + c + d + 5 * e) == 200)
    p.st( 5 * b - (a + b + c + d + 5 * e) == 200)
    p.st( 8 * c - (a + b + c + d + 5 * e) == 200)
    p.st(10 * d - (a + b + c + d + 5 * e) == 200)
    p.st(40 * e - (a + b + c + d + 5 * e) == 200)
    
    p.solve()
    
    for v in (a, b, c, d, e):
      printf("{v.name} = {v.primal}")
    

    Solution: The stakes were as follows: £250 on Bonnie Lass; £200 on Golden Stirrup; £125 on Two’s A Crowd; £100 on Greek Hero; £25 on each of the remaining five horses.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: