3
ClySuva
6y

So I had an interesting problem... Let's say I have X lights which will turn on or off after I pull a lever. I know the probability of each one of them turning on, but they are all different. I want to know what is the probability of at least half of them being on after I pull the lever.

I wrote this shit show to do it: https://jsbin.com/jizocohebo/edit/...

Can you do better?

Comments
  • 0
    I may be missing something but cant you just sum the values in the array and divide by the number of items? Basically find the mean probability. Eg.
    (0.1 + 0.2 + 0.3 + 0.4 ) / 4 = 0.25
  • 0
    I do know how it shd be done in the most unoptimised way ever.
    (I am not math geek tbh)
    I mean for eg. If there are 2 lights .
    And we have P1 and P2 .the probability of atleast half of them being on would be.
    P1(1-p2) + P2(1-p1) + p1p2
    Adding up proablities of all the cases possible.
    I am pretty dumb I can't think any better. 😅
  • 0
    @halfflat beautiful. Can you now port it to JS. :D
  • 0
    @halfflat hey, looks beautiful. I don't get exactly what is the math behind it, but seems to work perfect and code looks fairly decent as well. Good job. :D
Add Comment