Skip to content

Commit

Permalink
Find the smallest
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 10, 2024
1 parent 124c8f4 commit 4baacec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions kyu_5/find_the_smallest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Find the smallest."""
17 changes: 10 additions & 7 deletions kyu_5/find_the_smallest/solution.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
"""
Solution for -> Find the smallest
Solution for -> Find the smallest.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


def get_min_digit(digits: list) -> int:
"""
Find a min
Find min digit.
:param digits: list
:return: int
"""
min_digit = min(digits)
return min_digit
return min(digits)


def concat_new_n(digits: list, min_digit: int, min_index: int) -> list:
"""
Find new n
Find new n.
:param digits: list
:param min_digit: int
:param min_index: int
Expand All @@ -33,7 +35,7 @@ def concat_new_n(digits: list, min_digit: int, min_index: int) -> list:
del digits[min_index]
else:
while digits[min_index] == 0:
if min_index - 1 >= 0:
if min_index >= 1:
min_index -= 1
else:
break
Expand All @@ -58,6 +60,8 @@ def concat_new_n(digits: list, min_digit: int, min_index: int) -> list:

def smallest(n: int) -> list:
"""
smallest function.
Return an array or a tuple or a string depending on the language
(see "Sample Tests") with:
Expand All @@ -72,7 +76,6 @@ def smallest(n: int) -> list:
:return: an array with: smallest number, index, digit
"""
digits: list = [int(char) for char in str(n)]

min_digit = get_min_digit(digits)
min_index = ''.join([str(d) for d in digits]).rindex(str(min_digit))

Expand Down
13 changes: 7 additions & 6 deletions kyu_5/find_the_smallest/test_smallest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Find the smallest
Test for -> Find the smallest.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand Down Expand Up @@ -27,14 +28,14 @@
@pytest.mark.skip(reason="The solution is not ready")
# pylint: enable-msg=R0801
class FindSmallestTestCase(unittest.TestCase):
"""
Testing smallest function
"""
"""Testing smallest function."""

def test_smallest(self):
"""
Test a function `smallest` which will return an array or a tuple or a string
depending on the language (see "Sample Tests").
Testing smallest function with various test data.
Test a function `smallest` which will return an array or a
tuple or a string depending on the language (see "Sample Tests").
:return:
"""
# pylint: disable-msg=R0801
Expand Down

0 comments on commit 4baacec

Please sign in to comment.