Here’s a run file that can be executed directly.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#!/usr/bin/env python -m enigma -r SubstitutedExpression --answer="LEMONS" # each team has played 5 matches "W = 5" # won + lost + drawn = 5 "O + N <= 5" "S + O + M = 5" "L + O <= 5" "S <= 5" # goals for >= won, goals against >= lost "E >= S" "S >= 5 - L - O" "T >= L" "O >= (E - S) // 3" "(E - S) % 3 = 0" # points (= 3*won + drawn) are all different "all_different(3 * O + (5 - O - N), 3 * S + M, 3 * (5 - L - O) + O, E)" |

The code can be executed on repl.it. [ https://repl.it/@jim_r/teaser2893 ]

We could provide additional constraints (W=5; L,M,N,O,S are 0,1,2,3,4 (in some order)) but id doesn’t make much difference to the run time.

]]>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from itertools import permutations W = 5 for O, N, S, M, L in permutations(range(5)): if S + O + M == 5 and O + N <= 5 and L + O <= 5: WC = 5 - L - O # wins by City if WC <= S: # City must have scored at least as many goals as wins # calculate points for Albion, Borough, City PA = 3 * O + (5 - O - N) PB = 3 * S + M PC = 3 * (5 - L - O) + O # E is the number of points scored by Friday if len(set((PA, PB, PC))) == 3: for E in set(range(10))-set(( W, O, N, S, M, L, PA, PB, PC)): # Friday must have no more draws than points # Friday's points for wins must be a multiple of 3, # and Friday's number of wins + draws is at most 5 if E >= S and (E - S) % 3 == 0 and (E - S) // 3 + S <= 5: WF = (E - S) // 3 # wins by Friday if WF <= O: # Friday must have no more wins than goals scored print "LEMONS =", L, E, M, O, N, S print "\n\tP W L D F A Pts" print "Albion\t{} {} {} {} ? ? {}".format(W, O, N, 5 - O - N, PA) print "Borough\t5 {} {} {} {} ? {}".format(S, O, M, E, PB) print "City \t5 {} {} {} {} ? {}".format(WC, L, O, S, PC) print "Friday\t5 {} {} {} {} {} {}".format(WF, 5 - WF - S, S, O, M, E) |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
from functools import reduce from football import Football f = Football('ABCDEF', outcomes='ldw', scoring={'w':3, 'd':1}, sep='') # save solutions here sol = set() # consider possible points scored in each of A's games for d1 in f.games(dict(), 'A'): # compile a table of results and check that they give # valid values for A's results in their letter form At = f.table(d1, 'A') W, O, N = At.p, At.w, At.l s3 = {N, O, W} if len(s3) != 3 or not all(0 <= x < 10 for x in s3): continue # repeat the process for B's remaining games for d2 in f.games(d1, 'B'): Bt = f.table(d2, 'B') S, o, M = Bt.w, Bt.l, Bt.d s5 = s3.union([M, S]) if (Bt.pts == At.pts or o != O or len(s5) != 5 or not all(0 <= x < 10 for x in s5)): continue # ... and C's for d3 in f.games(d2, 'C'): Ct = f.table(d3, 'C') L, o = Ct.l, Ct.d s6 = s5.union([L]) if (Ct.pts in {At.pts, Bt.pts} or o != O or len(s6) != 6 or not all(0 <= x < 10 for x in s6)): continue # now complete the remaining games for D, E and F for d4 in f.games(d3, 'D'): for d5 in f.games(d4, 'E'): for d6 in f.games(d5, 'F'): Dt = f.table(d6, 'D') Et = f.table(d6, 'E') Ft = f.table(d6, 'F') # check F's letter symbol results are valid if Ft.d != S or Ft.pts in s6 or not 0 <= Ft.pts < 10: continue pts, E = {x.pts for x in (At, Bt, Ct, Dt, Et, Ft)}, Ft.pts # the are no ties on points if len(pts) == 6: lemons = reduce(lambda x, y: 10 * x + y, (L, E, M, O, N, S)) # consider possible values for T for T in set(range(10)).difference(s6.union([E])): # find match results for C that are compatible with their loss, # draw and win results and their goals for and goals against for d7 in f.matches(d6, 'C', S, T): # find match results for F that are compatible with their loss, # draw, win results and their goals for and goals against for d8 in f.matches(d7, 'F', O, M): sol.add(lemons) print('LEMONS = {}'.format(*sol)) |