From 4baacec9c2291c46a2f190911e1c858a301f7ac7 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Mon, 9 Dec 2024 19:29:13 -0800 Subject: [PATCH] Find the smallest --- kyu_5/find_the_smallest/__init__.py | 1 + kyu_5/find_the_smallest/solution.py | 17 ++++++++++------- kyu_5/find_the_smallest/test_smallest.py | 13 +++++++------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/kyu_5/find_the_smallest/__init__.py b/kyu_5/find_the_smallest/__init__.py index e69de29bb2d..cc9b55ae4b4 100644 --- a/kyu_5/find_the_smallest/__init__.py +++ b/kyu_5/find_the_smallest/__init__.py @@ -0,0 +1 @@ +"""Find the smallest.""" diff --git a/kyu_5/find_the_smallest/solution.py b/kyu_5/find_the_smallest/solution.py index c2559e93817..b1bafd7bcae 100644 --- a/kyu_5/find_the_smallest/solution.py +++ b/kyu_5/find_the_smallest/solution.py @@ -1,5 +1,6 @@ """ -Solution for -> Find the smallest +Solution for -> Find the smallest. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,17 +8,18 @@ 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 @@ -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 @@ -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: @@ -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)) diff --git a/kyu_5/find_the_smallest/test_smallest.py b/kyu_5/find_the_smallest/test_smallest.py index 8aeb9a42501..7f93e597a14 100644 --- a/kyu_5/find_the_smallest/test_smallest.py +++ b/kyu_5/find_the_smallest/test_smallest.py @@ -1,5 +1,6 @@ """ -Test for -> Find the smallest +Test for -> Find the smallest. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -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