Sort by

recency

|

85 Discussions

|

  • + 0 comments
    import math as m 
    
    def calculate_percent_cdf(mean, stdev, x):
        p = (1/2 * (1 + m.erf((x-mean)/(stdev*m.sqrt(2)))))*100
        return p
    
    if __name__ == '__main__':        
        # read input
        mean, std = map(int, input().split())
        x1 = int(input())
        x2 = int(input())
        
        # calculate percentages
        p1 = 100 - calculate_percent_cdf(mean, std, x1)
        p2 = 100 - calculate_percent_cdf(mean, std, x2)
        p3 = calculate_percent_cdf(mean, std, x2)
        
        # print results
        print(round(p1, 2))
        print(round(p2, 2))
        print(round(p3, 2))
    
  • + 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'{(1 - cdf(70,10,80))*100:.2f}')
    print(f'{(1 - cdf(70,10,60))*100:.2f}')
    print(f'{cdf(70,10,60)*100:.2f}')
    
  • + 0 comments
    public class Solution {
    
        public static void main(String[] args) {
            double mean = 70;
            double stdDeviation = 10;
            double x1 = 80, x2 = 60;
            
            double result1 = 1 - probability(mean, stdDeviation, x1);
            double result3 = probability(mean, stdDeviation, x2);
            double result2 = 1 - result3;
            
            System.out.println(round(result1*100));
            System.out.println(round(result2*100));
            System.out.println(round(result3*100));
        }
        
        public static double probability(double mean, double stdDeviation, double x) {
            final double z = calcZ(mean, stdDeviation, x);
            return 1 - (1 + erf(z)) / 2;
        }
    
        public static double calcZ(double mean, double stdDeviation, double x) {
            return (mean - x) / (stdDeviation * Math.sqrt(2));
        }
    
        public static double erf(double z) {
            double sum = 0;
            for (int n = 0; n < 11; n++) {
                double sfsfsf = z / (2 * n + 1);
                for (int i = 1; i <= n; i++) sfsfsf *= -z * z / i;
                sum += sfsfsf;
            }
            return 2 / Math.sqrt(Math.PI) * sum;
        }
    
        static double round(double v) {
            return Math.round(v * 100)*1d/100;
        }
    }
    
  • + 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 value = input.split(/[ \n]/g);
        let h = 100 * (1 - (0.5 * (1 + erf((parseFloat(value[2]) - parseFloat(value[0])) / (parseFloat(value[1]) * Math.sqrt(2.0))))));
        let m = 100 * (1 - (0.5 * (1 + erf((parseFloat(value[3]) - parseFloat(value[0])) / (parseFloat(value[1]) * Math.sqrt(2.0))))));
        let l = 100 * (0.5 * (1 + erf((parseFloat(value[3]) - parseFloat(value[0])) / (parseFloat(value[1]) * Math.sqrt(2.0)))));
        console.log(h.toFixed(2));
        console.log(m.toFixed(2));
        console.log(l.toFixed(2));
    
  • + 0 comments
    import math
    
    def cdf_(grades_, mu_, sigma_):
        probability_ = 0.5 * (1 + math.erf((grades_ - mu_)/(sigma_ * math.sqrt(2))))
        return probability_ * 100
    
    mean_, st_dev_ = map(float, input().split())
    grade_pass = float(input())
    grade_fail = float(input())
    
    print(round(100 - cdf_(grade_pass, mean_, st_dev_), 2))
    print(round(100 - cdf_(grade_fail, mean_, st_dev_), 2))
    print(round(cdf_(grade_fail, mean_, st_dev_), 2))