Skip to content

Commit 10c4fd6

Browse files
author
Kalpak Take
authored
Create min.py
Find min or smallest number in data
1 parent 5bd3b3b commit 10c4fd6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

algorithms/analysis/min.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
5+
# Finds the minium number
6+
# in un-sorted data
7+
8+
# Sudo Algo:
9+
# Iterate through data
10+
# each time a number(say k) is less than previous
11+
# consideration(say p), replace previous
12+
# consideration(p) with that smaller number(k)
13+
# By this way,
14+
# At last we get the smallest(minium) number from data
15+
16+
def min_(seq):
17+
min_n = seq[0]
18+
for item in seq[1:]:
19+
if item < min_n:
20+
min_n = item
21+
return min_n
22+
23+
24+
# Test
25+
# Add your tests too!
26+
tests = [[9017289, 782367, 736812903, 9367821, 71256716278, 676215, 2398, 0, 1],
27+
[19208, 9239, 4376, 738, 78, 51, 5, 6, 12, 78, 123, 65765, 1999999999],
28+
[1, 2, 4, 7, 9]]
29+
30+
# checking our functions results
31+
# with python's built-in min() function
32+
for test_i in range(len(tests)):
33+
m = min_(tests[test_i])
34+
if m == min(tests[test_i]):
35+
print("Min number in array({}) -> ".format(test_i + 1) + str(m))
36+
else:
37+
print("Oops! Someting went wrong!")

0 commit comments

Comments
 (0)