Last active
January 4, 2025 21:04
-
-
Save evgenii-malov/4ebfdf1173efc5ed8e686e7eb67ae46e 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
{- | |
binomial-distribution-1: https://www.hackerrank.com/challenges/binomial-distribution-1/ | |
Author: Evgeniy Malov <[email protected]> | |
Date: Jan 4, 2025 | |
join me : https://www.youtube.com/@EvgeniyMalov | |
https://ru.linkedin.com/in/deepwalk | |
-} | |
import Text.Printf (printf) | |
-- 4 shots | |
-- more than 2 hits - it is equal to | |
-- A - event of 3 or 4 hits | |
-- P(A) = ? | |
-- B = 1 miss | |
-- P(A) = 1 - P(B) = ? | |
-- at least 3 misses | |
-- A - 3 or 4 misses | |
-- B - 1 hit or 0 hits | |
-- P(A) = 1 - P(B) | |
-- P(K) = C(N,K)*P^K*Q^(N-K) | |
fac 0 = 1 | |
fac n = n*(fac $ n - 1) | |
cnk k n = (fac n) `div` ( (fac (n - k)) * fac (k)) | |
binp n k p = (fromIntegral (cnk k n)) * (p ^ k) * ((1 - p)^(n-k)) | |
p :: Double | |
p = 4 / 5 | |
p1 = binp 4 3 p + binp 4 4 p | |
p2 = binp 4 1 p + binp 4 0 p | |
main = do | |
printf "%.3f\n" p1 | |
printf "%.3f" p2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment