Skip to content

Instantly share code, notes, and snippets.

@asemic-horizon
Created August 24, 2023 16:31
Show Gist options
  • Save asemic-horizon/8f691f9923348c33497c2f34c8d2f39a to your computer and use it in GitHub Desktop.
Save asemic-horizon/8f691f9923348c33497c2f34c8d2f39a to your computer and use it in GitHub Desktop.
from math import sqrt
def _hsmode(zs,f):
if len(zs)==1:
return zs[0]
elif len(zs)==2:
return f(zs[0],zs[1])
else:
h = len(zs)//2
if (zs[h]-zs[0]) < (zs[-1]-zs[h+1]):
return _hsmode(zs[:h],f)
else:
return _hsmode(zs[h:],f)
def calc_hsmode(xs,f):
return _hsmode(sorted(xs),f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment