# any more efficient function than ContainsAny?

 prob[tot_, sub_] :=
Length[Select[Subsets[Range[tot], {5}], ContainsAny[Range[sub]]]]/
combinat[tot, 5]   enter code here


this works but as tot goes up, say 60 it takes time, and cpu can warm coffee, so my questions is ContainsAny ... looks like the bottleneck .. is there a more efficient way ?

• IntersectingQ seems to be faster than ContainsAny
– kglr
Feb 1 '20 at 21:52
• What is it you're actually after, seems like an x-y question... In any case, use inclusion-exclusion, or just do it directly: pr[t_,s_]:=1/120 s (24+s^4-5 s^3 (-2+t)+5 (-4+t) t (5+(-4+t) t)-5 s (-2+t) (5+2 (-4+t) t)+5 s^2 (7+2 (-4+t) t))...
– ciao
Feb 1 '20 at 22:06

prb[tot_, sub_] := 1 - Binomial[tot - sub, 5]/Binomial[tot, 5]