2019-07-21 06:16:28 +00:00
|
|
|
from .abs import abs_val
|
|
|
|
|
2019-07-11 16:20:41 +00:00
|
|
|
|
2018-11-03 20:08:13 +00:00
|
|
|
def absMin(x):
|
|
|
|
"""
|
2019-07-21 06:16:28 +00:00
|
|
|
>>> absMin([0,5,1,11])
|
2018-11-03 20:08:13 +00:00
|
|
|
0
|
2019-07-21 06:16:28 +00:00
|
|
|
>>> absMin([3,-10,-2])
|
2018-11-03 20:08:13 +00:00
|
|
|
-2
|
|
|
|
"""
|
2018-12-04 17:18:32 +00:00
|
|
|
j = x[0]
|
2018-11-03 20:08:13 +00:00
|
|
|
for i in x:
|
2019-07-11 16:20:41 +00:00
|
|
|
if abs_val(i) < abs_val(j):
|
2018-11-03 20:08:13 +00:00
|
|
|
j = i
|
|
|
|
return j
|
|
|
|
|
2019-07-21 06:16:28 +00:00
|
|
|
|
2018-11-03 20:08:13 +00:00
|
|
|
def main():
|
2018-12-04 17:18:32 +00:00
|
|
|
a = [-3,-1,2,-11]
|
|
|
|
print(absMin(a)) # = -1
|
2018-11-03 20:08:13 +00:00
|
|
|
|
2019-07-21 06:16:28 +00:00
|
|
|
|
2018-11-03 20:08:13 +00:00
|
|
|
if __name__ == '__main__':
|
2018-12-04 17:32:53 +00:00
|
|
|
main()
|