• + 0 comments

    Python simple and clean solution:

    x = [95, 85, 80, 70, 60]
    y = [85, 95, 70, 65, 70]
    
    sum_x = sum(x)
    sum_y = sum(y)
    n = len(x) # or len(y)
    
    b = (n * sum(x[i] * y[i] for i in range(n))) - (sum_x * sum_y)
    b /= n * sum(list(map(lambda i: i*i, x))) - sum_x ** 2
    # or b /= n * sum(i ** 2 for i in x) - sum_x ** 2
    
    mean_x = sum_x / n
    mean_y = sum_y / n
    
    a = mean_y - b * mean_x
    
    print(a + b * 80)