Skip to content

Instantly share code, notes, and snippets.

@slbug

slbug/t.nb Secret

Last active December 14, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slbug/88b19f5b3f9e32961f46 to your computer and use it in GitHub Desktop.
Save slbug/88b19f5b3f9e32961f46 to your computer and use it in GitHub Desktop.
matches[wins_, tickets_] := Length[DeleteCases[Map[match[tickets, #] &, wins], {}]] == Length[wins];
match[tickets_, win_] := Select[tickets, Intersection[#, win] == win &, 1];
f[n_, k_, p_] := (
field = Range[n];
If[n == k, Return[{field}]];
wins = Subsets[field, {k}];
If[k == p, Return[wins]];
tickets = Join[wins, Subsets[field, {k + 1, p}]];
tc = Select[Subsets[tickets], Union[Flatten[#]] == field &];
pw = Select[tc, matches[wins, #] &];
Return[First[SortBy[pw, Length]]];
);
f[4,2,3]
(* {{1, 2}, {1, 3, 4}, {2, 3, 4}} *)
f[5,2,3]
(* {{1, 2, 3}, {1, 2, 4}, {1, 2, 5}, {3, 4, 5}} *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment