-
-
Save slbug/88b19f5b3f9e32961f46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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