Created
July 21, 2017 21:43
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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