• + 0 comments
    def solve(balls):
        r = 0
        n = len(balls)
        for i in range(0, n):
            # in half of the combinations (2**(n)), each ball is not picked
            # so we can compute its aggregated contribution to the final value as
    				r += 2**(n-1)*balls[i] 
        ev = r/(2**n) # expected value
        return "%.1f"%ev
    `