Skip to content

Instantly share code, notes, and snippets.

@schuyler
Last active September 14, 2020 15:21
Show Gist options
  • Save schuyler/d953781aed1318d7302ce90669fc076f to your computer and use it in GitHub Desktop.
Save schuyler/d953781aed1318d7302ce90669fc076f to your computer and use it in GitHub Desktop.
Prolog script to choose teams for single-elimination "survivor" pools
% ?- schedule(W), pick(W, T).
%
% pick(season, league) picks favorites for each week in the season, selecting
% each team no more than once.
pick([], []).
pick([Week|Rest_of_Season], [Team|Rest_of_League]) :-
faves(Week, Faves),
is_in(Team, Faves),
pick(Rest_of_Season, Rest_of_League),
not_in(Team, Rest_of_League).
% faves() identifies the teams favored to win by 7 or more points for each week
% in the league schedule.
faves(w1, [kc, ind, bal, ne, sf]).
faves(w2, [ten, tb, cle, dal]).
faves(w3, [phi, cle, ind, sf]).
faves(w4, [bal, kc, lar, tb]).
faves(w5, [bal, sf, kc, no, dal, hou]).
faves(w6, [ind, sf]).
faves(w7, [no, bal]).
faves(w8, [kc, lac]).
faves(w9, [kc, min]).
faves(w10, [gb, pit]).
faves(w11, [no, bal]).
faves(w12, [dal, min]).
faves(w13, [min, kc, pit, sea]).
faves(w14, [sf, kc, sea]).
faves(w15, [bal, gb, lar]).
faves(w16, [bal, kc, hou]).
faves(w17, [ind, kc, phi, bal, buf, no, ne, tb]).
% schedule() just lists the weeks in the season.
schedule([w1, w2, w3, w4, w5, w6, w7, w8, w9,
w10, w11, w12, w13, w14, w15, w16, w17]).
% These predicates support the selection of teams.
is_in(X, [X | _]).
is_in(X, [_ | T]) :- is_in(X, T).
not_in(_, []).
not_in(X, [X | _]) :- !, fail().
not_in(X, [_ | T]) :- not_in(X, T).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment