Skip to content

Instantly share code, notes, and snippets.

@damontallen
Created July 12, 2016 14:52
Show Gist options
  • Save damontallen/68a20bd3823b5fad2022ae6ab87c6748 to your computer and use it in GitHub Desktop.
Save damontallen/68a20bd3823b5fad2022ae6ab87c6748 to your computer and use it in GitHub Desktop.
A recursion version of the built-in min function in Python.
def MIN(X):
"returns the minimum value in a list of numbers"
if len(X)>2:
x = X[0]
y = MIN(X[1:])
else:
x,y = X
sn = (x-y)/(2*abs(x-y))
b = (x*(0.5-sn)+y*(sn+0.5))
return b
MIN([2,3,1,-7])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment