We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 10 Days of Statistics
  4. Day 4: Binomial Distribution I
  5. Discussions

Day 4: Binomial Distribution I

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Sort 209 Discussions, By:

recency

Please Login in order to post a comment

  • shashinp1996
    2 weeks ago+ 0 comments

    JS

      function range(a,b) {
            let prd = a,i = a;
            while (i++< b) {
                prd*=i;
            }
            return prd;
        }
        function comb(n, r) {
            if (n==r || r==0) return 1;
            else {
                r=(r < n-r) ? n-r : r;
                return range(r+1, n)/range(1,n-r);
            }
        }
        let value = input.split(' ');
        let p = parseFloat(value[0])/(parseFloat(value[1]) + parseFloat(value[0]));
        let q = 1-p, b =[];
        for(let i = 3; i <= 6; i++) {
            let f = comb(6, i) * Math.pow(p, i) * Math.pow(q, (6 - i));
            b.push(f);
        }
        console.log((b.reduce((sum, a) => sum + a, 0)).toFixed(3));
    
    0|
    Permalink
  • ppanasta
    4 weeks ago+ 0 comments

    I did the following with scipy but it is not accepted , is this because for some reason we cannot use scipy ?

    from scipy.stats import binom sum=0 for i in range (3,6+1): sum+=binom.pmf(i,6,1-(1/2.09)) #print(binom.pmf(i,6,1-(1/2.09)))

    print(round(sum,3))

    0|
    Permalink
  • axlyeyo2000
    2 months ago+ 0 comments

    import math

    binomial = lambda x,n,q,p : math.comb(n, x)*(p**x)(q*(n - x))

    rb = 1.09 rg = 1

    p = rb/(rb + rg) q = 1 - p

    n = 6

    P = [binomial(x, n, q, p) for x in range(3,7)]

    print(round(sum(P),3))

    0|
    Permalink
  • sabsfilho
    3 months ago+ 0 comments
    static void Main(String[] args) {
    	var zs = System.Console.ReadLine().Split(' ');
    	double b = double.Parse(zs[0]); 
    	double g = double.Parse(zs[1]);
    	int bs = 3;
    	int chs = 6;       
    	double sum = 0;
    	double pb = b / (g + b);
    	double pg = 1.0 - pb;
    	for(int i = bs;i<=chs;i++){
    		sum += comb(chs, i) * Math.Pow(pb,i) * Math.Pow(pg, (chs-i));
    	}
    	System.Console.WriteLine(Math.Round(sum,3).ToString("f3"));
    }
    
    static double comb(double n, double r){
    	var nf = f(n);
    	var rf = f(r);
    	var nrf = f(n-r);
    	return nf / ( rf * (nrf));
    }
    
    static double f(double i)
    {
    	if (i < 2){
    		i = 1;
    	}
    	double l = i;
    	while(i-->1){
    		l = l*i;
    	}
    	return l;
    }
    
    0|
    Permalink
  • ayeshaghazi
    3 months ago+ 0 comments
    import math
    
    boys, girls = map(float, input().split())
    p_boys = boys/(boys + girls)
    p_girls = 1 - p_boys
    b = []
    n_children = 6
    n_boys = 3
    for i in range(n_boys, n_children+1):
        answer = math.comb(6, i) * (p_boys ** i) * (p_girls ** (n_children - i))
        b.append(answer)
        
    print(round(sum(b), 3))
    
    1|
    Permalink
Load more conversations

Need Help?


View tutorial
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy