Skip to content

Instantly share code, notes, and snippets.

@sundhaug92
Created July 21, 2017 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sundhaug92/612efdc401d3db6b3d267ce8d71dc1ac to your computer and use it in GitHub Desktop.
Save sundhaug92/612efdc401d3db6b3d267ce8d71dc1ac to your computer and use it in GitHub Desktop.
Proof that, for any set, it's either true that all elements are equal or that atleast one element has a higher value than the average
'''
Proof that, for any set, it's either true that all elements are equal or that atleast one element has a higher value than the average
'''
def avg(a):
'''
Calculate average over a set, list, array or similar
'''
return sum(a)/len(a)
def f(a):
'''
Test the claim for a given array
'''
if len(a)<2:return True
if any([_>=avg(a) for _ in a]):return True
return False
'''
Test the claim for n<100 (should be enough)
'''
all([f(list(range(_))) for _ in range(100)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment