Enigmatic Code

Programming Enigma Puzzles

Enigma 520: Fifteen goals, but find the scores

From New Scientist #1672, 8th July 1989 [link]

Five football teams, A, B, C, D and E, are to play each other once. After some of the matches have been played a table giving some details of matches played, won, lost and so on looked like this:

Enigma 520

Find the score in each match.

[enigma520]

One response to “Enigma 520: Fifteen goals, but find the scores

  1. Jim Randell 7 October 2019 at 7:53 am

    We can solve this puzzle using the [[ Football() ]] helper class from the enigma.py library.

    The following Python program runs in 343ms.

    Run: [ @repl.it ]

    from enigma import Football, digit_map
    
    football = Football(games="wdlx")
    
    # the table and goals for/against columns
    (table, gf, ga) = (dict(played="??2??", w="???12", l="111??", d="0??00"), "10725", "25422")
    
    # digits stand for themselves
    d = digit_map(0, 7)
    
    # find possible match outcomes
    for (ms, _) in football.substituted_table(table, d=d):
    
      # find possible scores
      for ss in football.substituted_table_goals(gf, ga, ms, d=d):
    
        football.output_matches(ms, ss, teams="ABCDE")
    

    Solution: The scores in the played matches are: A vs D = 1 – 2; B vs C = 0 – 5; C vs E = 2 – 4; D vs E = 0 – 1.

    The A vs B, A vs C, A vs E, B vs D, B vs E, C vs D matches are not yet played.

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: