Skip to content

Instantly share code, notes, and snippets.

@jiaweih
Created March 29, 2016 00:02
Show Gist options
  • Save jiaweih/e4d6f297f143a91d5bea to your computer and use it in GitHub Desktop.
Save jiaweih/e4d6f297f143a91d5bea to your computer and use it in GitHub Desktop.
# Enter your code here. Read input from STDIN. Print output to STDOUT
import sys
import math
def get_std(lst):
length = len(lst)
summ = sum(lst)
average = reduce(lambda x, y: x + y, lst) / length
std = 0
for i in lst:
std += (i - average)**2
std = std * 1.0 / length
std = math.sqrt(std)
return std
inputs = [line for line in sys.stdin]
old_lst = [int(n) for n in inputs]
old_std = round(get_std(old_lst),3)
N = []
i = 0
while i < 3:
new_lst = old_lst + [i]
new_std = get_std(new_lst)
if abs(new_std - old_std) < 0.001:
N.append(round(i,2))
i += 0.001
print max(N)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment