Created
August 24, 2023 16:31
-
-
Save asemic-horizon/8f691f9923348c33497c2f34c8d2f39a to your computer and use it in GitHub Desktop.
This file contains 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
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