Sort by

recency

|

50 Discussions

|

  • + 0 comments
    #python
    import math
    def cdf(m, std, x):
        return 0.5 * (1 + math.erf((x-m)/(std*2**.5)))
    n, m0, std0, x=100, 2.4, 2, 250
    m=n*m0
    std=math.sqrt(n)*std0
    print(round(cdf(m, std, x), 4))
    
  • + 0 comments
    import math as m
    def cdf(mn, std, x):
        return 1/2 * (1 + m.erf((x-mn)/(std*m.sqrt(2))))
    print(f'{cdf(2.4*100, 2*m.sqrt(100), 250):.4f}')
    
  • + 0 comments
    double mean = 2.4;
    double stdDev = 2.0;
    int nStudents = 100;
    int nTickets = 250;
    
    double meanX = mean * nStudents;
    double stdDevX = stdDev * Math.sqrt(nStudents);
    
    double p = probability(meanX, stdDevX, nTickets);
    

    The probability is calculated in the same way as in the "Day 5: Normal Distribution I" problem.

  • + 0 comments

    JS

      function erf(x) {
            var a1 = 0.254829592;
            var a2 = -0.284496736;
            var a3 = 1.421413741;
            var a4 = -1.453152027;
            var a5 = 1.061405429;
            var p = 0.3275911;
            var sign = 1;
            if (x < 0) {
                sign = -1;
            }
            x = Math.abs(x);
            var t = 1.0 / (1.0 + p * x);
            var y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * Math.exp(-x * x);
            return sign * y;
        }
         let arr = input.split(/[\n]/g);
         let st = (parseFloat(arr[0]) - (parseInt(arr[1]) * parseFloat(arr[2]))) / (Math.sqrt(parseInt(arr[1])) * parseFloat(arr[3]));
         let ans = (1.0 + erf(st / Math.sqrt(2.0))) / 2.0;
        console.log(ans.toFixed(4));
    
  • + 0 comments

    Python Solution

    using Z Score

    from math import *
    def Zscore(x):
        return (1.0 + erf(x / sqrt(2.0))) / 2.0
    
    sumN = int(input())
    n = int(input())
    u = float(input())
    o = float(input())
    
    pr = (sumN - n*u) / (sqrt(n) * o)
    x = Zscore(pr)
    print(round(x, 4))