Created
July 12, 2016 14:52
-
-
Save damontallen/68a20bd3823b5fad2022ae6ab87c6748 to your computer and use it in GitHub Desktop.
A recursion version of the built-in min function in Python.
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
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