1
$\begingroup$
 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 ?

$\endgroup$
2
  • 2
    $\begingroup$ IntersectingQ seems to be faster than ContainsAny $\endgroup$
    – kglr
    Feb 1 '20 at 21:52
  • 3
    $\begingroup$ 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))... $\endgroup$
    – ciao
    Feb 1 '20 at 22:06
3
$\begingroup$

Try Binomial:

prb[tot_, sub_] := 1 - Binomial[tot - sub, 5]/Binomial[tot, 5]
$\endgroup$
1
  • $\begingroup$ Excellent ... you really know the ropes and the knots! I pretended to make same rule trying with small sets ... but don't arrive to any rule at analitic way and moved to brute force... Thanks $\endgroup$ Feb 1 '20 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.