Day 6: The Central Limit Theorem II | 10 Days Of Statistics | HackerRank Solution

Hello coders, today we are going to solve Day 6: The Central Limit Theorem II HackerRank Solution which is a Part of 10 Days of Statistics Series.

Day 6: The Central Limit Theorem II

Objective

In this challenge, we practice solving problems based on the Central Limit Theorem.

Task

The number of tickets purchased by each student for the University X vs. University Y football game follows a distribution that has a mean of u = 2.4 and a standard deviation of o = 2.0.

A few hours before the game starts, 100 eager students line up to purchase last-minute tickets. If there are only 250 tickets left, what is the probability that all 100 students will be able to purchase tickets?

Input Format

There are 4 lines of input (shown below):

250
100
2.4
2.0

The first line contains the number of last-minute tickets available at the box office. The second line contains the number of students waiting to buy tickets. The third line contains the mean number of purchased tickets, and the fourth line contains the standard deviation.

If you do not wish to read this information from stdin, you can hard-code it into your program.

Output Format

Print the probability that 100 students can successfully purchase the remaining 250 tickets, rounded to a scale of 4 decimal places (i.e., 1.2345 format).

Solution – The Central Limit Theorem II

C++

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


double normal_dist(double m, double sd, double x)
{   
    
    double p = 0.5*(1 + erf((x-m)/(sd*sqrt(2.0))));
    return p; 
}

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    
    double m = 100*2.4, sd = sqrt(100)*2.0, x = 250;
    
    printf("%0.4f", normal_dist(m, sd, x));
    
    return 0;
}

Disclaimer: The above Problem (The Central Limit Theorem II) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *