Skip to content

Instantly share code, notes, and snippets.

@dmah42
Created March 11, 2021 09:28
Show Gist options
  • Save dmah42/e0d040b154da5ed0ca19997fdad076e2 to your computer and use it in GitHub Desktop.
Save dmah42/e0d040b154da5ed0ca19997fdad076e2 to your computer and use it in GitHub Desktop.
geothmetic meandian (https://xkcd.com/2435/)
import statistics
def has_converged(xs):
return all(x == xs[0] for x in xs)
def f(xs):
return [
statistics.mean(xs),
statistics.median(xs),
statistics.geometric_mean(xs)
]
def gmdn(xs):
while not has_converged(xs):
print('.', end='')
xs = f(xs)
print('\n')
return xs
print(gmdn([1, 1, 2, 3, 5]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment