From d9ec5de847f6715f02c98c6047833b548b576381 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Wed, 4 Dec 2024 20:55:52 -0800 Subject: [PATCH 01/50] Create pydocstyle_kyu4.yml --- .github/workflows/pydocstyle_kyu4.yml | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/pydocstyle_kyu4.yml diff --git a/.github/workflows/pydocstyle_kyu4.yml b/.github/workflows/pydocstyle_kyu4.yml new file mode 100644 index 00000000000..fb5fab4f43d --- /dev/null +++ b/.github/workflows/pydocstyle_kyu4.yml @@ -0,0 +1,46 @@ +--- +name: pydocstyle for kyu4 + +on: # yamllint disable-line rule:truthy + push: + branches: + - 'kyu4' + +permissions: + contents: read + pull-requests: read + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.x"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + # This is the version of the action for setting up Python, + # not the Python version. + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + # You can test your matrix by printing the current Python version + - name: Display Python version + run: python -c "import sys; print(sys.version)" + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools wheel + pip install -r requirements.txt + pip install pydocstyle + pip install types-requests + - name: Check to make sure that the module is in your Python path + run: | + echo $PYTHONPATH + - name: Check pydocstyle version + run: | + pydocstyle --version + - name: Doc style checking with pydocstyle + # Pydocstyle testing (Guide) + # https://www.pydocstyle.org/en/stable/usage.html#cli-usage + run: | + pydocstyle --verbose --explain --count kyu_4 From aa72e900c2e861221cfd7e0da443f84adae198f7 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Thu, 5 Dec 2024 20:17:39 -0800 Subject: [PATCH 02/50] __init__ docstring --- kyu_4/__init__.py | 1 + kyu_4/human_readable_duration_format/__init__.py | 1 + kyu_4/most_frequently_used_words/__init__.py | 1 + kyu_4/next_bigger_number_with_the_same_digits/__init__.py | 1 + kyu_4/next_smaller_number_with_the_same_digits/__init__.py | 1 + kyu_4/permutations/__init__.py | 1 + kyu_4/range_extraction/__init__.py | 1 + kyu_4/snail/__init__.py | 1 + kyu_4/strings_mix/README.md | 4 ++-- kyu_4/strings_mix/__init__.py | 1 + kyu_4/strip_comments/__init__.py | 1 + kyu_4/sudoku_solution_validator/__init__.py | 1 + kyu_4/sum_by_factors/__init__.py | 1 + kyu_4/sum_of_intervals/__init__.py | 1 + kyu_4/the_greatest_warrior/__init__.py | 1 + kyu_4/validate_sudoku_with_size/__init__.py | 1 + 16 files changed, 17 insertions(+), 2 deletions(-) diff --git a/kyu_4/__init__.py b/kyu_4/__init__.py index e69de29bb2d..f4a82f04020 100644 --- a/kyu_4/__init__.py +++ b/kyu_4/__init__.py @@ -0,0 +1 @@ +"""Codewars kyu_4 package.""" diff --git a/kyu_4/human_readable_duration_format/__init__.py b/kyu_4/human_readable_duration_format/__init__.py index e69de29bb2d..056c0879651 100644 --- a/kyu_4/human_readable_duration_format/__init__.py +++ b/kyu_4/human_readable_duration_format/__init__.py @@ -0,0 +1 @@ +"""Human readable duration format package.""" diff --git a/kyu_4/most_frequently_used_words/__init__.py b/kyu_4/most_frequently_used_words/__init__.py index e69de29bb2d..c288a6188db 100644 --- a/kyu_4/most_frequently_used_words/__init__.py +++ b/kyu_4/most_frequently_used_words/__init__.py @@ -0,0 +1 @@ +"""Most frequently used words in a text package.""" diff --git a/kyu_4/next_bigger_number_with_the_same_digits/__init__.py b/kyu_4/next_bigger_number_with_the_same_digits/__init__.py index e69de29bb2d..30dc3d22713 100644 --- a/kyu_4/next_bigger_number_with_the_same_digits/__init__.py +++ b/kyu_4/next_bigger_number_with_the_same_digits/__init__.py @@ -0,0 +1 @@ +"""Next bigger number with the same digits package.""" diff --git a/kyu_4/next_smaller_number_with_the_same_digits/__init__.py b/kyu_4/next_smaller_number_with_the_same_digits/__init__.py index e69de29bb2d..da3bbbb87c5 100644 --- a/kyu_4/next_smaller_number_with_the_same_digits/__init__.py +++ b/kyu_4/next_smaller_number_with_the_same_digits/__init__.py @@ -0,0 +1 @@ +"""Next smaller number with the same digits package.""" diff --git a/kyu_4/permutations/__init__.py b/kyu_4/permutations/__init__.py index e69de29bb2d..942250b3c8e 100644 --- a/kyu_4/permutations/__init__.py +++ b/kyu_4/permutations/__init__.py @@ -0,0 +1 @@ +"""Permutations package.""" diff --git a/kyu_4/range_extraction/__init__.py b/kyu_4/range_extraction/__init__.py index e69de29bb2d..732db55fa77 100644 --- a/kyu_4/range_extraction/__init__.py +++ b/kyu_4/range_extraction/__init__.py @@ -0,0 +1 @@ +"""Range Extraction package.""" diff --git a/kyu_4/snail/__init__.py b/kyu_4/snail/__init__.py index e69de29bb2d..6ececdca848 100644 --- a/kyu_4/snail/__init__.py +++ b/kyu_4/snail/__init__.py @@ -0,0 +1 @@ +"""Snail Sort package.""" diff --git a/kyu_4/strings_mix/README.md b/kyu_4/strings_mix/README.md index c09c168468d..0904770cf61 100644 --- a/kyu_4/strings_mix/README.md +++ b/kyu_4/strings_mix/README.md @@ -1,8 +1,8 @@ # Strings Mix -Given two strings `s1` and `s2`, we want to visualize how different the +****Given two strings `s1` and `s2`, we want to visualize how different the two strings are. We will only take into account the lowercase letters -(a to z). First let us count the frequency of each lowercase letters in +(a to z). Fir****st let us count the frequency of each lowercase letters in `s1` and `s2`. ```text diff --git a/kyu_4/strings_mix/__init__.py b/kyu_4/strings_mix/__init__.py index e69de29bb2d..19cbec43a11 100644 --- a/kyu_4/strings_mix/__init__.py +++ b/kyu_4/strings_mix/__init__.py @@ -0,0 +1 @@ +"""Strings Mix package.""" diff --git a/kyu_4/strip_comments/__init__.py b/kyu_4/strip_comments/__init__.py index e69de29bb2d..62779246461 100644 --- a/kyu_4/strip_comments/__init__.py +++ b/kyu_4/strip_comments/__init__.py @@ -0,0 +1 @@ +"""Strip Comments package.""" diff --git a/kyu_4/sudoku_solution_validator/__init__.py b/kyu_4/sudoku_solution_validator/__init__.py index e69de29bb2d..c5bdd87d16e 100644 --- a/kyu_4/sudoku_solution_validator/__init__.py +++ b/kyu_4/sudoku_solution_validator/__init__.py @@ -0,0 +1 @@ +"""Sudoku Solution Validator package.""" diff --git a/kyu_4/sum_by_factors/__init__.py b/kyu_4/sum_by_factors/__init__.py index e69de29bb2d..e426b1ef6d1 100644 --- a/kyu_4/sum_by_factors/__init__.py +++ b/kyu_4/sum_by_factors/__init__.py @@ -0,0 +1 @@ +"""Sum by Factors package.""" diff --git a/kyu_4/sum_of_intervals/__init__.py b/kyu_4/sum_of_intervals/__init__.py index e69de29bb2d..bf777c72502 100644 --- a/kyu_4/sum_of_intervals/__init__.py +++ b/kyu_4/sum_of_intervals/__init__.py @@ -0,0 +1 @@ +"""Sum of Intervals package.""" diff --git a/kyu_4/the_greatest_warrior/__init__.py b/kyu_4/the_greatest_warrior/__init__.py index e69de29bb2d..68f8ffb6c20 100644 --- a/kyu_4/the_greatest_warrior/__init__.py +++ b/kyu_4/the_greatest_warrior/__init__.py @@ -0,0 +1 @@ +"""The Greatest Warrior package.""" diff --git a/kyu_4/validate_sudoku_with_size/__init__.py b/kyu_4/validate_sudoku_with_size/__init__.py index e69de29bb2d..e73604e7e84 100644 --- a/kyu_4/validate_sudoku_with_size/__init__.py +++ b/kyu_4/validate_sudoku_with_size/__init__.py @@ -0,0 +1 @@ +"""Validate Sudoku with size `NxN` package.""" From 0ec0eeebfa922b1c510165b2eb8100b55489b262 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Thu, 5 Dec 2024 20:22:51 -0800 Subject: [PATCH 03/50] Update next_smaller.py --- .../next_smaller.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kyu_4/next_smaller_number_with_the_same_digits/next_smaller.py b/kyu_4/next_smaller_number_with_the_same_digits/next_smaller.py index a0dfe8eb090..493628defdc 100644 --- a/kyu_4/next_smaller_number_with_the_same_digits/next_smaller.py +++ b/kyu_4/next_smaller_number_with_the_same_digits/next_smaller.py @@ -1,5 +1,6 @@ """ -Solution for -> Next smaller number with the same digits +Solution for -> Next smaller number with the same digits. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,10 +8,13 @@ def next_smaller(n: int) -> int: """ + next_smaller function. + A function that takes a positive integer and returns the next smaller positive integer containing the same digits. - If no smaller number can be composed using those digits, return -1 + :param n: int + :return: int """ # 1 # Starting from the right, find the index of the first digit that @@ -41,7 +45,8 @@ def next_smaller(n: int) -> int: def find_x(n: int) -> int: """ - Find x + Find x. + :param n: int :return: int """ @@ -54,7 +59,8 @@ def find_x(n: int) -> int: def find_y(n: int, x_i: int) -> int: """ - Find y + Find y. + :param n: int :param x_i: int :return: int @@ -75,4 +81,4 @@ def find_y(n: int, x_i: int) -> int: if comparable_x['y'] < y: comparable_x['y'] = y comparable_x['index'] = index + x_i + 1 - return comparable_x['index'] if comparable_x['index'] else -1 + return comparable_x['index'] or -1 From 61946fece7cb8b77f69d17cdbd4014892c074f15 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Thu, 5 Dec 2024 20:23:43 -0800 Subject: [PATCH 04/50] Update test_next_smaller.py --- .../test_next_smaller.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kyu_4/next_smaller_number_with_the_same_digits/test_next_smaller.py b/kyu_4/next_smaller_number_with_the_same_digits/test_next_smaller.py index 0e1ad4b4264..2bb5262c59e 100644 --- a/kyu_4/next_smaller_number_with_the_same_digits/test_next_smaller.py +++ b/kyu_4/next_smaller_number_with_the_same_digits/test_next_smaller.py @@ -1,5 +1,6 @@ """ -Test for -> Next smaller number with the same digits +Test for -> Next smaller number with the same digits. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -29,13 +30,11 @@ name='Source/Kata') # pylint: enable-msg=R0801 class NextSmallerTestCase(unittest.TestCase): - """ - Testing next_smaller function - """ + """Testing next_smaller function.""" def test_next_smaller(self): """ - Testing next_smaller function + Testing next_smaller function. You have to test a function that takes a positive integer number and returns the next smaller number formed by the same digits: @@ -45,6 +44,7 @@ def test_next_smaller(self): 2071 ==> 2017 If no smaller number can be composed using those digits, return -1 + :return: """ # pylint: disable-msg=R0801 allure.dynamic.title("Testing next_smaller function") From 9c1d1330e171c0de14c42dbb170f195a20cd39cd Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Thu, 5 Dec 2024 20:36:23 -0800 Subject: [PATCH 05/50] Update format_duration.py --- .../format_duration.py | 143 +++++++++--------- 1 file changed, 72 insertions(+), 71 deletions(-) diff --git a/kyu_4/human_readable_duration_format/format_duration.py b/kyu_4/human_readable_duration_format/format_duration.py index 3bf8955a6a3..4706fb41930 100644 --- a/kyu_4/human_readable_duration_format/format_duration.py +++ b/kyu_4/human_readable_duration_format/format_duration.py @@ -1,4 +1,6 @@ """ +Format duration. + A function which formats a duration, given as a number of seconds, in a human-friendly way. Created by Egor Kostan. @@ -8,6 +10,8 @@ def format_duration(seconds: int) -> str: """ + format_duration function. + A function which formats a duration, given as a number of seconds, in a human-friendly way. @@ -67,34 +71,36 @@ def format_duration(seconds: int) -> str: return result -def format_days(days: int, day: str, result: str) -> str: +def format_days(days: int, + day: str, + result: str) -> str: """ - Format days for the final string - :param days: - :param day: - :param result: - :return: + Format days for the final string. + + :param days: int + :param day: str + :param result: str + :return: str """ - if days > 0 and result != '': - result += f', {day}' - elif days > 0: - result += f'{day}' + if days > 0: + result += f', {day}' if result else f'{day}' return result -def format_hours(hours: int, hour: str, result: str) -> str: +def format_hours(hours: int, + hour: str, + result: str) -> str: """ - Format hours for the final string - :param hours: - :param hour: - :param result: - :return: + Format hours for the final string. + + :param hours: int + :param hour: str + :param result: str + :return: str """ - if hours > 0 and result != '': - result += f', {hour}' - elif hours > 0: - result += f'{hour}' + if hours > 0: + result += f', {hour}' if result else f'{hour}' return result @@ -104,12 +110,13 @@ def format_minutes(minutes: int, minute: str, result: str) -> str: """ - Format minutes for the final string - :param minutes: - :param seconds: - :param minute: - :param result: - :return: + Format minutes for the final string. + + :param minutes: int + :param seconds: int + :param minute: str + :param result: str + :return: str """ if minutes > 0 and result != '' and seconds == 0: result += f' and {minute}' @@ -123,26 +130,27 @@ def format_minutes(minutes: int, def format_seconds(seconds: int, second: str, result: str) -> str: """ - Format seconds for the final string - :param seconds: - :param second: - :param result: - :return: + Format seconds for the final string. + + :param seconds: int + :param second: str + :param result: str + :return: str """ - if seconds > 0 and result != '': - result += f' and {second}' - elif seconds > 0: - result += f'{second}' + if seconds > 0: + result += f' and {second}' if result else f'{second}' return result -def get_string(number: int, string: str) -> str: +def get_string(number: int, + string: str) -> str: """ - Concatenate string result - :param number: - :param string: - :return: + Concatenate string result. + + :param number: int + :param string: str + :return: str """ result: str = '' if number == 1: @@ -155,59 +163,52 @@ def get_string(number: int, string: str) -> str: def calc_seconds(seconds: int) -> int: """ - Calculate seconds - :param seconds: - :return: - """ - if seconds < 60: - return seconds + Calculate seconds. - return seconds % 60 + :param seconds: int + :return: int + """ + return seconds if seconds < 60 else seconds % 60 def calc_minutes(seconds: int) -> int: """ - calculate minutes - :param seconds: - :return: + Calculate minutes. + + :param seconds: int + :return: int """ minutes = seconds // 60 - if minutes < 60: - return minutes - - return minutes % 60 + return minutes if minutes < 60 else minutes % 60 def calc_hours(seconds: int) -> int: """ - Calculate hours - :param seconds: - :return: + Calculate hours. + + :param seconds: int + :return: int """ hours = seconds // (60 * 60) - if hours < 24: - return hours - - return hours % 24 + return hours if hours < 24 else hours % 24 def calc_days(seconds: int) -> int: """ - Calculate days - :param seconds: - :return: + Calculate days. + + :param seconds: int + :return: int """ days = seconds // (60 * 60 * 24) - if days < 365: - return days - - return days % 365 + return days if days < 365 else days % 365 def calc_years(seconds: int) -> int: """ - Calculate years - :param seconds: - :return: + Calculate years. + + :param seconds: int + :return: int """ return seconds // (60 * 60 * 24 * 365) From 5f867a0675ca81b075e03ee2eddbff27018d8c8d Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Thu, 5 Dec 2024 20:36:26 -0800 Subject: [PATCH 06/50] Update test_format_duration.py --- .../test_format_duration.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kyu_4/human_readable_duration_format/test_format_duration.py b/kyu_4/human_readable_duration_format/test_format_duration.py index 0f498dc6ba2..6580a672242 100644 --- a/kyu_4/human_readable_duration_format/test_format_duration.py +++ b/kyu_4/human_readable_duration_format/test_format_duration.py @@ -1,5 +1,6 @@ """ -Test for 'Human readable duration format' +Test for 'Human readable duration format'. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -29,12 +30,12 @@ name='Source/Kata') # pylint: enable-msg=R0801 class FormatDurationTestCase(unittest.TestCase): - """ - Testing format_duration - """ + """Testing format_duration.""" def test_format_duration(self): """ + Test format_duration function. + Test a function which formats a duration, given as a number of seconds, in a human-friendly way. From 8065547268798a7e491415b25ecab6d689400b6f Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Thu, 5 Dec 2024 20:38:05 -0800 Subject: [PATCH 07/50] Update solution.py --- kyu_4/most_frequently_used_words/solution.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kyu_4/most_frequently_used_words/solution.py b/kyu_4/most_frequently_used_words/solution.py index 89813390c35..3557d1b8bd8 100644 --- a/kyu_4/most_frequently_used_words/solution.py +++ b/kyu_4/most_frequently_used_words/solution.py @@ -1,5 +1,6 @@ """ -Most frequently used words in a text +Most frequently used words in a text. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def top_3_words(text: str) -> list: """ + Top 3 words function. + Given a string of text (possibly with punctuation and line-breaks), returns an array of the top-3 most occurring words, in descending order of the number of occurrences. From 04e42e7ac0d375d1580ecb8f5b12c3a5c2d87f54 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Thu, 5 Dec 2024 20:38:09 -0800 Subject: [PATCH 08/50] Update test_top_3_words.py --- kyu_4/most_frequently_used_words/test_top_3_words.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kyu_4/most_frequently_used_words/test_top_3_words.py b/kyu_4/most_frequently_used_words/test_top_3_words.py index 3e4c70af713..54e0dd1133a 100644 --- a/kyu_4/most_frequently_used_words/test_top_3_words.py +++ b/kyu_4/most_frequently_used_words/test_top_3_words.py @@ -1,5 +1,6 @@ """ -Test for 'Most frequently used words in a text' +Test for 'Most frequently used words in a text'. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -28,13 +29,13 @@ url='https://www.codewars.com/kata/51e056fe544cf36c410000fb', name='Source/Kata') class Top3WordsTestCase(unittest.TestCase): - """ - Testing top_3_words - """ + """Testing top_3_words.""" def test_top_3_words(self): """ - Test top_3_words function + Test top_3_words function with various test data. + + :return: """ # pylint: disable-msg=R0801 allure.dynamic.title("Testing top_3_words function") From 2e6dde6e01f8c8ae333c50ddb0263b83bc169349 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Thu, 5 Dec 2024 20:40:44 -0800 Subject: [PATCH 09/50] Update next_bigger.py --- .../next_bigger.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py b/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py index 889ff900f9b..bd50df22896 100644 --- a/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py +++ b/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py @@ -1,5 +1,6 @@ """ -Solution for -> Next bigger number with the same digits +Solution for -> Next bigger number with the same digits. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -62,11 +63,8 @@ def next_greater_digit_index(digits: list, i: int) -> int: return i for index, digit in enumerate(digits[i:]): - if digits[i - 1] < digit: - if current == '': - current = digit - j = i + index - elif current > digit: - current = digit - j = i + index + if digits[i - 1] < digit and (current == '' or current > digit): + current = digit + j = i + index + return j From df80c28c6417e8b718a525482432d45107ab2ba4 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Fri, 6 Dec 2024 08:13:39 -0800 Subject: [PATCH 10/50] Update sudoku.py --- kyu_4/validate_sudoku_with_size/sudoku.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/kyu_4/validate_sudoku_with_size/sudoku.py b/kyu_4/validate_sudoku_with_size/sudoku.py index 690964f1d95..f7ddc1d14d5 100644 --- a/kyu_4/validate_sudoku_with_size/sudoku.py +++ b/kyu_4/validate_sudoku_with_size/sudoku.py @@ -1,5 +1,6 @@ """ -Solution for -> Validate Sudoku with size `NxN` +Solution for -> Validate Sudoku with size `NxN`. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -15,6 +16,8 @@ class Sudoku: """ + Sudoku class. + Given a Sudoku data structure with size `NxN, N > 0 and √N == integer`, write a method to validate if it has been filled out correctly. @@ -25,6 +28,8 @@ def __init__(self, data: list): def is_valid(self) -> bool: """ + Sudoku validator. + A method to validate if given a Sudoku has been filled out correctly. Sudoku -> data structure with size NxN, N > 0 and √N == integer. :return: bool @@ -34,22 +39,22 @@ def is_valid(self) -> bool: or not assert_sudoku_by_column(self.__data): return False - if len(self.__data) > 1: - if not assert_sudoku_by_region(self.__data): - return False + if len(self.__data) > 1 and not assert_sudoku_by_region(self.__data): + return False return True def is_data_valid(self) -> bool: """ - Verify data validity + Verify data validity. + :return: bool """ if not self.__data: return False - if len(self.__data) == 1: - if self.__data[0][0] != 1 or isinstance(self.__data[0][0], bool): - return False + if (len(self.__data) == 1 and + (self.__data[0][0] != 1 or isinstance(self.__data[0][0], bool))): + return False return isinstance(self.__data, list) From bbda02556fca8f62e8c241cbeda010895fa5fda7 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Fri, 6 Dec 2024 08:14:21 -0800 Subject: [PATCH 11/50] Update test_sudoku.py --- kyu_4/validate_sudoku_with_size/test_sudoku.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kyu_4/validate_sudoku_with_size/test_sudoku.py b/kyu_4/validate_sudoku_with_size/test_sudoku.py index 7f4ad1a461d..e1967c1b7dc 100644 --- a/kyu_4/validate_sudoku_with_size/test_sudoku.py +++ b/kyu_4/validate_sudoku_with_size/test_sudoku.py @@ -1,5 +1,6 @@ """ -Test for -> Validate Sudoku with size `NxN` +Test for -> Validate Sudoku with size `NxN`. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -27,13 +28,11 @@ url='https://www.codewars.com/kata/540afbe2dc9f615d5e000425', name='Source/Kata') class SudokuTestCase(unittest.TestCase): - """ - Testing Sudoku class - """ + """Testing Sudoku class.""" def test_sudoku_class(self): """ - Testing Sudoku class + Testing Sudoku class. Given a Sudoku data structure with size NxN, N > 0 and √N == integer, assert a method that validates if it has been filled out correctly. @@ -160,7 +159,8 @@ def test_sudoku_class(self): [7, 8, 9, 1, 2, 3, 4, 5, 6], [8, 9, 7, 2, 3, 1, 5, 6, 4], [9, 7, 8, 3, 1, 2, 6, 4, 5]], - False, 'Sudoku with invalid boxes (little squares), but valid rows and columns')) + False, 'Sudoku with invalid boxes (little squares),' + 'but valid rows and columns')) for data, expected, message in test_data: with allure.step("Enter a Sudoku solution and verify if it a valid one."): From 59302cd74f1021a67e00837e68f4e2f0c8712293 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Fri, 6 Dec 2024 08:17:34 -0800 Subject: [PATCH 12/50] Update test_battle.py --- kyu_4/the_greatest_warrior/test_battle.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kyu_4/the_greatest_warrior/test_battle.py b/kyu_4/the_greatest_warrior/test_battle.py index 811d30edc09..046c46c27fb 100644 --- a/kyu_4/the_greatest_warrior/test_battle.py +++ b/kyu_4/the_greatest_warrior/test_battle.py @@ -1,5 +1,6 @@ """ -Test for -> The Greatest Warrior -> test battle +Test for -> The Greatest Warrior -> test battle. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -30,13 +31,13 @@ name='Source/Kata') # pylint: enable-msg=R0801 class BattleTestCase(unittest.TestCase): - """ - Testing Battle method - """ + """Testing Battle method.""" def test_battle(self): """ - Testing Battle method + Testing Battle method with various test data. + + :return: """ # pylint: disable-msg=R0801 allure.dynamic.title("Testing Battle method") From e6033c01dfe718ebe2a4c46ca5b56375773485e4 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Fri, 6 Dec 2024 08:23:34 -0800 Subject: [PATCH 13/50] Update sum_of_intervals.py --- kyu_4/sum_of_intervals/sum_of_intervals.py | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/kyu_4/sum_of_intervals/sum_of_intervals.py b/kyu_4/sum_of_intervals/sum_of_intervals.py index 0130532696e..444bc889d34 100644 --- a/kyu_4/sum_of_intervals/sum_of_intervals.py +++ b/kyu_4/sum_of_intervals/sum_of_intervals.py @@ -1,5 +1,6 @@ """ -Solution for -> Sum of Intervals +Solution for -> Sum of Intervals. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -11,30 +12,26 @@ def sum_of_intervals(intervals: list) -> int: the sum of all the interval lengths. Overlapping intervals should only be counted once. - :param intervals: - :return: + :param intervals: list + :return: int """ intervals = remove_overlaps(intervals) - results: list = [] - - for i in intervals: - results.append(i[1] - i[0]) - + results: list = [(i[1] - i[0]) for i in intervals] return sum(results) def remove_overlaps(intervals: list) -> list: """ - Remove overlaps and duplicates - :param intervals: - :return: + Remove overlaps and duplicates. + + :param intervals: list + :return: int """ is_clean: bool = False while not is_clean: is_clean = True - for index_i, i in enumerate(intervals): for index_b, b in enumerate(intervals): if index_b != index_i: @@ -45,13 +42,16 @@ def remove_overlaps(intervals: list) -> list: return intervals -def clean_interval(intervals, i, b) -> bool: +def clean_interval(intervals: list, + i: tuple, + b: tuple) -> bool: """ - Remove intervals - :param intervals: - :param i: - :param b: - :return: + Remove intervals. + + :param intervals: list + :param i: tuple + :param b: tuple + :return: bool """ result: bool = True From 148da83eeb4e06e3383ce3e1b2826218e3df7cc8 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Fri, 6 Dec 2024 08:24:06 -0800 Subject: [PATCH 14/50] Update test_sum_of_intervals.py --- kyu_4/sum_of_intervals/test_sum_of_intervals.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kyu_4/sum_of_intervals/test_sum_of_intervals.py b/kyu_4/sum_of_intervals/test_sum_of_intervals.py index 29d7c9e6923..fe9253cf5c1 100644 --- a/kyu_4/sum_of_intervals/test_sum_of_intervals.py +++ b/kyu_4/sum_of_intervals/test_sum_of_intervals.py @@ -1,5 +1,6 @@ """ -Test for -> Sum of Intervals +Test for -> Sum of Intervals. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -27,13 +28,11 @@ @allure.link(url='https://www.codewars.com/kata/52b7ed099cdc285c300001cd', name='Source/Kata') class SumOfIntervalsTestCase(unittest.TestCase): - """ - Testing sum_of_intervals function - """ + """Testing sum_of_intervals function.""" def test_sum_of_intervals(self): """ - Testing sum_of_intervals function + Testing sum_of_intervals function. The function should accept an array of intervals, and return the sum of all the interval lengths. From 0f932e0d480673a46e8073d50af788a52e084210 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Fri, 6 Dec 2024 08:27:27 -0800 Subject: [PATCH 15/50] Update sum_for_list.py --- kyu_4/sum_by_factors/sum_for_list.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kyu_4/sum_by_factors/sum_for_list.py b/kyu_4/sum_by_factors/sum_for_list.py index c5669a25289..523d0b93569 100644 --- a/kyu_4/sum_by_factors/sum_for_list.py +++ b/kyu_4/sum_by_factors/sum_for_list.py @@ -1,5 +1,6 @@ """ -Solution for -> sum_for_list function +Solution for -> sum_for_list function. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -9,7 +10,9 @@ def sum_for_list(lst: list) -> list: """ - Given an array of positive or negative integers I= [i1,..,in] + Sorting an array by increasing order. + + Given an array of positive or negative integers I= [i1,...,in] the function have to produce a sorted array P of the form: [ [p, sum of all ij of I for which p is a prime factor (p positive) of ij] ...] @@ -39,12 +42,12 @@ def sum_for_list(lst: list) -> list: m = -1 if digit % (prime * m) == 0: - if len(temp) == 0: + if not temp: temp.append(prime) sum_digits += digit # add result in case prime in temp list - if len(temp) > 0: + if temp: temp.append(sum_digits) results.append(temp) From a4bc2c38508d1d0f25a7da036ab70b9614f988e3 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Fri, 6 Dec 2024 08:29:50 -0800 Subject: [PATCH 16/50] Update test_battle.py ./kyu_4/the_greatest_warrior/test_battle.py:39:1: W293 blank line contains whitespace """ Testing Battle method with various test data. :return: """ ^ ./kyu_4/the_greatest_warrior/test_battle.py:40:17: W291 trailing whitespace """ Testing Battle method with various test data. :return: """ --- kyu_4/the_greatest_warrior/test_battle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kyu_4/the_greatest_warrior/test_battle.py b/kyu_4/the_greatest_warrior/test_battle.py index 046c46c27fb..79ed0ac0e66 100644 --- a/kyu_4/the_greatest_warrior/test_battle.py +++ b/kyu_4/the_greatest_warrior/test_battle.py @@ -36,8 +36,8 @@ class BattleTestCase(unittest.TestCase): def test_battle(self): """ Testing Battle method with various test data. - - :return: + + :return: """ # pylint: disable-msg=R0801 allure.dynamic.title("Testing Battle method") From 90d3293fa9182b0dd64c4ccf88a24075e9dabc85 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:14:58 -0800 Subject: [PATCH 17/50] Update test_valid_solution.py --- .../sudoku_solution_validator/test_valid_solution.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kyu_4/sudoku_solution_validator/test_valid_solution.py b/kyu_4/sudoku_solution_validator/test_valid_solution.py index a0c08843d60..65e27d6b58b 100644 --- a/kyu_4/sudoku_solution_validator/test_valid_solution.py +++ b/kyu_4/sudoku_solution_validator/test_valid_solution.py @@ -1,5 +1,6 @@ """ -Test for -> Sudoku Solution Validator +Test for -> Sudoku Solution Validator. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -24,12 +25,12 @@ @allure.link(url='https://www.codewars.com/kata/529bf0e9bdf7657179000008', name='Source/Kata') class ValidSolutionTestCase(unittest.TestCase): - """ - Testing validSolution function - """ + """Testing validSolution function.""" def test_valid_solution(self): """ + Test valid_solution function. + Test a function validSolution/ValidateSolution/valid_solution() that accepts a 2D array representing a Sudoku board, and returns true if it is a valid solution, or false otherwise. The cells of @@ -42,7 +43,7 @@ def test_valid_solution(self): :return: """ # pylint: disable-msg=R0801 - allure.dynamic.title("Testing validSolution") + allure.dynamic.title("Testing valid_solution") allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '

Codewars badge:

' From feb9d585943ed871e19bb3f7062a494c9b6825ba Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:18:17 -0800 Subject: [PATCH 18/50] Update valid_solution.py --- .../valid_solution.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/kyu_4/sudoku_solution_validator/valid_solution.py b/kyu_4/sudoku_solution_validator/valid_solution.py index 64530a3a2cc..84e02f9ff21 100644 --- a/kyu_4/sudoku_solution_validator/valid_solution.py +++ b/kyu_4/sudoku_solution_validator/valid_solution.py @@ -1,5 +1,6 @@ """ -Solution for -> Sudoku Solution Validator +Solution for -> Sudoku Solution Validator. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -20,9 +21,10 @@ def valid_solution(board: list) -> bool: def check_horizontally(board: list) -> bool: """ - test horizontally - :param board: - :return: + Test horizontally. + + :param board: list + :return: bool """ for row in board: if sorted(row) != [1, 2, 3, 4, 5, 6, 7, 8, 9]: @@ -32,14 +34,15 @@ def check_horizontally(board: list) -> bool: def check_vertically(board: list) -> bool: """ - test vertically + Test vertically. + :param board: :return: """ i: int = 0 while i < 9: - col = [] + col: list = [] for row in board: col.append(row[i]) if sorted(col) != [1, 2, 3, 4, 5, 6, 7, 8, 9]: @@ -50,21 +53,22 @@ def check_vertically(board: list) -> bool: def check_sub_grids(board: list) -> bool: """ - test each of the nine 3x3 sub-grids + Test each of the nine 3x3 sub-grids. + (also known as blocks) :param board: :return: """ sub_grids: list = [ - board[0][0:3] + board[1][0:3] + board[2][0:3], + board[0][:3] + board[1][:3] + board[2][:3], board[0][3:6] + board[1][3:6] + board[2][3:6], board[0][6:] + board[1][6:] + board[2][6:], - board[3][0:3] + board[4][0:3] + board[5][0:3], + board[3][:3] + board[4][:3] + board[5][:3], board[3][3:6] + board[4][3:6] + board[5][3:6], board[3][6:] + board[4][6:] + board[5][6:], - board[6][0:3] + board[7][0:3] + board[8][0:3], + board[6][:3] + board[7][:3] + board[8][:3], board[6][3:6] + board[7][3:6] + board[8][3:6], board[6][6:] + board[7][6:] + board[8][6:], ] From 01775eec5f3f29f0bcdb7c90e3dcc527842cfaa6 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:20:19 -0800 Subject: [PATCH 19/50] Update solution.py --- kyu_4/strip_comments/solution.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kyu_4/strip_comments/solution.py b/kyu_4/strip_comments/solution.py index 6a3b065b3f5..7d7fac4512a 100644 --- a/kyu_4/strip_comments/solution.py +++ b/kyu_4/strip_comments/solution.py @@ -1,5 +1,6 @@ """ -Solution for -> Strip Comments +Solution for -> Strip Comments. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def solution(string: str, markers: list) -> str: """ + Strip comments solution. + The solution strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line will be stripped out as well. From 76d6d86f5cb8b2ee44d93935a4f61bc0acfdb5ab Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:20:23 -0800 Subject: [PATCH 20/50] Update test_solution.py --- kyu_4/strip_comments/test_solution.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kyu_4/strip_comments/test_solution.py b/kyu_4/strip_comments/test_solution.py index 68e78a365c7..20f5ab69343 100644 --- a/kyu_4/strip_comments/test_solution.py +++ b/kyu_4/strip_comments/test_solution.py @@ -1,5 +1,6 @@ """ -Test for -> Strip Comments +Test for -> Strip Comments. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -23,17 +24,16 @@ @allure.link(url='https://www.codewars.com/kata/51c8e37cee245da6b40000bd', name='Source/Kata') class SolutionTestCase(unittest.TestCase): - """ - Testing solution for Strip Comments problem - """ + """Testing solution for Strip Comments problem.""" def test_solution(self): """ - Testing 'solution' function + Testing 'solution' function. The solution should strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out. + :return: """ # pylint: disable-msg=R0801 allure.dynamic.title("Testing 'solution' function") From 92ef00e6cbff067d627f094e5939cce86cf0c5c8 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:22:36 -0800 Subject: [PATCH 21/50] Update solution.py --- kyu_4/strings_mix/solution.py | 39 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/kyu_4/strings_mix/solution.py b/kyu_4/strings_mix/solution.py index a73966a0bfa..66b621badd6 100644 --- a/kyu_4/strings_mix/solution.py +++ b/kyu_4/strings_mix/solution.py @@ -1,5 +1,6 @@ """ -Solution for -> Strings Mix +Solution for -> Strings Mix. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -11,6 +12,8 @@ def mix(s1: str, s2: str) -> str: """ + Mix function. + Given two strings s1 and s2, we want to visualize how different the two strings are. We will only take into account the lowercase letters (a to z). @@ -30,28 +33,33 @@ def mix(s1: str, s2: str) -> str: results: list = [] for key in keys: - if key in s2_results and key in s1_results: - if s1_results[key] == s2_results[key]: - results.append(f'=:{key * s1_results[key]}') - elif s1_results[key] > s2_results[key]: - results.append(f'1:{key * s1_results[key]}') - else: - results.append(f'2:{key * s2_results[key]}') + if ( + key in s2_results + and key in s1_results + and s1_results[key] == s2_results[key] + ): + results.append(f'=:{key * s1_results[key]}') + elif ( + key in s2_results + and key in s1_results + and s1_results[key] > s2_results[key] + or (key not in s2_results or key not in s1_results) + and key in s1_results + ): + results.append(f'1:{key * s1_results[key]}') else: - if key in s1_results: - results.append(f'1:{key * s1_results[key]}') - else: - results.append(f'2:{key * s2_results[key]}') - + results.append(f'2:{key * s2_results[key]}') return '/'.join(sort_results(results)) def sort_results(results: list) -> list: """ + Sorting results. + The results will be in decreasing order of their length and when they have the same length sorted in ascending lexicographic order (letters and digits - more precisely - sorted by code-point) + sorted by code-point). :param results: :return: """ @@ -76,7 +84,8 @@ def sort_results(results: list) -> list: def get_counters(s: str) -> dict: """ - Get counters + Get counters. + :param s: str :return: dict """ From ba92654a0c0c5db088dcba3e10bb40319f789f4a Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:24:27 -0800 Subject: [PATCH 22/50] Update snail_sort.py --- kyu_4/snail/snail_sort.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kyu_4/snail/snail_sort.py b/kyu_4/snail/snail_sort.py index 34f614c1144..9c8c0f73125 100644 --- a/kyu_4/snail/snail_sort.py +++ b/kyu_4/snail/snail_sort.py @@ -1,5 +1,5 @@ """ -Solution for -> Snail +Solution for -> Snail. Returns the array elements arranged from outermost elements to the middle element, traveling clockwise. @@ -11,6 +11,8 @@ def snail(snail_map: list) -> list: """ + Snail function. + Returns the array elements arranged from outermost elements to the middle element, traveling clockwise. From 6f66d5326530c8193bac773feb2c2b8941fe0235 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:24:31 -0800 Subject: [PATCH 23/50] Update test_snail.py --- kyu_4/snail/test_snail.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kyu_4/snail/test_snail.py b/kyu_4/snail/test_snail.py index 4e92c26f8b3..ef6002302f3 100644 --- a/kyu_4/snail/test_snail.py +++ b/kyu_4/snail/test_snail.py @@ -1,5 +1,5 @@ """ -Test for -> Snail +Test for -> Snail. Returns the array elements arranged from outermost elements to the middle element, traveling clockwise. @@ -28,17 +28,16 @@ @allure.link(url='https://www.codewars.com/kata/521c2db8ddc89b9b7a0000c1', name='Source/Kata') class SnailTestCase(unittest.TestCase): - """ - Testing snail function - """ + """Testing snail function.""" def test_snail(self): """ - Testing 'snail' function + Testing 'snail' function. Given an n x n array, 'snail' function should return the array elements arranged from outermost elements to the middle element, traveling clockwise. + :return: """ # pylint: disable-msg=R0801 allure.dynamic.title("Testing 'snail' function") From 6c815e1aba68411392b0d5a9eb2f131d963b0773 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:24:34 -0800 Subject: [PATCH 24/50] Update solution.py --- kyu_4/strings_mix/solution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_4/strings_mix/solution.py b/kyu_4/strings_mix/solution.py index 66b621badd6..bf1a7be3197 100644 --- a/kyu_4/strings_mix/solution.py +++ b/kyu_4/strings_mix/solution.py @@ -85,7 +85,7 @@ def sort_results(results: list) -> list: def get_counters(s: str) -> dict: """ Get counters. - + :param s: str :return: dict """ From cd76383a1126d58a85cfd8175c4b709f0d39c1dc Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:27:26 -0800 Subject: [PATCH 25/50] Update solution.py --- kyu_4/range_extraction/solution.py | 39 ++++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/kyu_4/range_extraction/solution.py b/kyu_4/range_extraction/solution.py index 6fc40883d8e..ddae106f55f 100644 --- a/kyu_4/range_extraction/solution.py +++ b/kyu_4/range_extraction/solution.py @@ -1,5 +1,6 @@ """ -Solution for -> Range Extraction +Solution for -> Range Extraction. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,10 +8,12 @@ def solution(args: list) -> str: """ + Solution for Range Extraction problem. + Tt takes a list of integers in increasing order and returns a correctly formatted string in the range format. - :param args: - :return: + :param args: list + :return: str """ current: list = [args[0], args[0], False] result: str = '' @@ -35,30 +38,34 @@ def solution(args: list) -> str: return result -def case_3(a: int, current: list, result: str) -> str: +def case_3(a: int, + current: list, + result: str) -> str: """ - Case #3 - :param a: - :param current: - :param result: - :return: + Case #3. + + :param a: int + :param current: list + :param result: str + :return: str """ if current[1] + 1 == a: current[1] = a result += str(current[0]) if abs(current[1] - current[0]) >= 2: - result += '-' + str(current[1]) + result += f'-{str(current[1])}' elif current[0] != current[1]: - result += ',' + str(current[1]) + result += f',{str(current[1])}' return result def case_2(**kwargs) -> str: """ - Case #2 - :return: + Case #2. + + :return: str """ a: int = kwargs['a'] i: int = kwargs['i'] @@ -72,11 +79,11 @@ def case_2(**kwargs) -> str: current[2] = True if abs(current[1] - current[0]) >= 2 and i != 1: - result += str(current[0]) + '-' + str(current[1]) + ',' + result += f'{str(current[0])}-{str(current[1])},' else: - result += str(current[0]) + ',' + result += f'{str(current[0])},' if current[0] != current[1]: - result += str(current[1]) + ',' + result += f'{str(current[1])},' current[0] = a current[1] = a From 0679925de25a0488753bf3f58954e1c764b3e6dc Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:28:59 -0800 Subject: [PATCH 26/50] Update permutations.py --- kyu_4/permutations/permutations.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kyu_4/permutations/permutations.py b/kyu_4/permutations/permutations.py index 68cbdcf0c72..aab6185389c 100644 --- a/kyu_4/permutations/permutations.py +++ b/kyu_4/permutations/permutations.py @@ -1,5 +1,6 @@ """ -Solution for -. Permutations +Solution for -. Permutations. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,10 +8,14 @@ def permutations(string: str) -> list: """ + Permutation function. + creates all permutations of an input string and remove duplicates, if present. This means, you have to shuffle all letters from the input in all possible orders. + :param string: str + :return: list """ for strg in string: print(strg) From c8e5477ac7db872216a1e4ce416f5401a49be110 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:29:02 -0800 Subject: [PATCH 27/50] Update test_permutations.py --- kyu_4/permutations/test_permutations.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kyu_4/permutations/test_permutations.py b/kyu_4/permutations/test_permutations.py index 04a4ffaecd6..b1ca433f5d4 100644 --- a/kyu_4/permutations/test_permutations.py +++ b/kyu_4/permutations/test_permutations.py @@ -1,5 +1,6 @@ """ -Solution for -. Permutations +Solution for -. Permutations. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -28,19 +29,18 @@ @pytest.mark.skip(reason="The solution is not ready") # pylint: enable-msg=R0801 class PermutationsTestCase(unittest.TestCase): - """ - Testing permutations function - """ + """Testing permutations function.""" def test_permutations(self): """ - Testing permutations function + Testing permutations function. Test that permutations function creates all permutations of an input string and remove duplicates, if present. This means, you have to shuffle all letters from the input in all possible orders. + :return: """ # pylint: disable-msg=R0801 allure.dynamic.title("Testing permutations function") From 2737838bcb3cf319baec52683bc61188222de8a6 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:31:18 -0800 Subject: [PATCH 28/50] Update solution.py ./kyu_4/strings_mix/solution.py:16:1: W293 blank line contains whitespace """ Mix function. Given two strings s1 and s2, we want to visualize how different the two strings are. We will only take into account the lowercase letters (a to z). First let us count the frequency of each lowercase letters in s1 and s2. :param s1: string a :param s2: string b :return: the difference between two strings """ --- kyu_4/strings_mix/solution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_4/strings_mix/solution.py b/kyu_4/strings_mix/solution.py index bf1a7be3197..e468f325812 100644 --- a/kyu_4/strings_mix/solution.py +++ b/kyu_4/strings_mix/solution.py @@ -13,7 +13,7 @@ def mix(s1: str, s2: str) -> str: """ Mix function. - + Given two strings s1 and s2, we want to visualize how different the two strings are. We will only take into account the lowercase letters (a to z). From f90c9b21e3e0fb64c3879db1dede732cb570233c Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:33:25 -0800 Subject: [PATCH 29/50] Update solution.py ./kyu_4/range_extraction/solution.py:12:1: W293 blank line contains whitespace """ Solution for Range Extraction problem. Tt takes a list of integers in increasing order and returns a correctly formatted string in the range format. :param args: list :return: str """ ^ ./kyu_4/range_extraction/solution.py:41:19: W291 trailing whitespace def case_3(a: int, ^ ./kyu_4/range_extraction/solution.py:42:26: W291 trailing whitespace current: list, ^ ./kyu_4/range_extraction/solution.py:46:1: W293 blank line contains whitespace """ Case #3. :param a: int :param current: list :param result: str :return: str """ ^ ./kyu_4/range_extraction/solution.py:67:1: W293 blank line contains whitespace """ Case #2. :return: str """ --- kyu_4/range_extraction/solution.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kyu_4/range_extraction/solution.py b/kyu_4/range_extraction/solution.py index ddae106f55f..b39d66d20b0 100644 --- a/kyu_4/range_extraction/solution.py +++ b/kyu_4/range_extraction/solution.py @@ -9,7 +9,7 @@ def solution(args: list) -> str: """ Solution for Range Extraction problem. - + Tt takes a list of integers in increasing order and returns a correctly formatted string in the range format. :param args: list @@ -38,12 +38,12 @@ def solution(args: list) -> str: return result -def case_3(a: int, - current: list, +def case_3(a: int, + current: list, result: str) -> str: """ Case #3. - + :param a: int :param current: list :param result: str @@ -64,7 +64,7 @@ def case_3(a: int, def case_2(**kwargs) -> str: """ Case #2. - + :return: str """ a: int = kwargs['a'] From b367e2c516fca3543df69a2aa12c8cfd1dbd2863 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:37:07 -0800 Subject: [PATCH 30/50] Update solution.py --- kyu_4/strings_mix/solution.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/kyu_4/strings_mix/solution.py b/kyu_4/strings_mix/solution.py index e468f325812..589f0eb6432 100644 --- a/kyu_4/strings_mix/solution.py +++ b/kyu_4/strings_mix/solution.py @@ -33,33 +33,30 @@ def mix(s1: str, s2: str) -> str: results: list = [] for key in keys: - if ( - key in s2_results - and key in s1_results - and s1_results[key] == s2_results[key] - ): - results.append(f'=:{key * s1_results[key]}') - elif ( - key in s2_results - and key in s1_results - and s1_results[key] > s2_results[key] - or (key not in s2_results or key not in s1_results) - and key in s1_results - ): - results.append(f'1:{key * s1_results[key]}') + if key in s2_results and key in s1_results: + if s1_results[key] == s2_results[key]: + results.append(f'=:{key * s1_results[key]}') + elif s1_results[key] > s2_results[key]: + results.append(f'1:{key * s1_results[key]}') + else: + results.append(f'2:{key * s2_results[key]}') else: - results.append(f'2:{key * s2_results[key]}') + if key in s1_results: + results.append(f'1:{key * s1_results[key]}') + else: + results.append(f'2:{key * s2_results[key]}') + return '/'.join(sort_results(results)) def sort_results(results: list) -> list: """ - Sorting results. + Sorting results function. The results will be in decreasing order of their length and when they have the same length sorted in ascending lexicographic order (letters and digits - more precisely - sorted by code-point). + sorted by code-point) :param results: :return: """ From dd4c341747f76c03cb3d2fa65f12a2e826abc37f Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:40:00 -0800 Subject: [PATCH 31/50] Update sudoku.py --- kyu_4/validate_sudoku_with_size/sudoku.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kyu_4/validate_sudoku_with_size/sudoku.py b/kyu_4/validate_sudoku_with_size/sudoku.py index f7ddc1d14d5..a311508e5a6 100644 --- a/kyu_4/validate_sudoku_with_size/sudoku.py +++ b/kyu_4/validate_sudoku_with_size/sudoku.py @@ -24,6 +24,11 @@ class Sudoku: """ def __init__(self, data: list): + """ + Create a new Sudoku instance. + + :param data: + """ self.__data: list = data def is_valid(self) -> bool: From 519769a93c15d34b9048d546364af3f53abc0126 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:41:03 -0800 Subject: [PATCH 32/50] Update test_mix.py --- kyu_4/strings_mix/test_mix.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kyu_4/strings_mix/test_mix.py b/kyu_4/strings_mix/test_mix.py index dec95adf8cd..5a441503863 100644 --- a/kyu_4/strings_mix/test_mix.py +++ b/kyu_4/strings_mix/test_mix.py @@ -1,5 +1,6 @@ """ -Test for -> Strings Mix +Test for -> Strings Mix. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -24,12 +25,11 @@ url='https://www.codewars.com/kata/5629db57620258aa9d000014', name='Source/Kata') class MixTestCase(unittest.TestCase): - """ - Testing solution for Strings Mix problem - """ + """Testing solution for Strings Mix problem.""" + def test_smix(self): """ - Testing 'mix' function + Testing 'mix' function. Given two strings s1 and s2, the 'mix' function should visualize how different the two strings are. From d39ff04996c4028f149addcc0c909ba16e87a90f Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:41:06 -0800 Subject: [PATCH 33/50] Update sudoku.py --- kyu_4/validate_sudoku_with_size/sudoku.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_4/validate_sudoku_with_size/sudoku.py b/kyu_4/validate_sudoku_with_size/sudoku.py index a311508e5a6..c93abcb06f9 100644 --- a/kyu_4/validate_sudoku_with_size/sudoku.py +++ b/kyu_4/validate_sudoku_with_size/sudoku.py @@ -26,7 +26,7 @@ class Sudoku: def __init__(self, data: list): """ Create a new Sudoku instance. - + :param data: """ self.__data: list = data From 224ba1142ca6377833b3ac0b51978ed5eb0cab94 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:42:55 -0800 Subject: [PATCH 34/50] Update test_solution.py --- kyu_4/range_extraction/test_solution.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kyu_4/range_extraction/test_solution.py b/kyu_4/range_extraction/test_solution.py index e7ee7fc8465..504099ff5c7 100644 --- a/kyu_4/range_extraction/test_solution.py +++ b/kyu_4/range_extraction/test_solution.py @@ -1,5 +1,6 @@ """ -Test for -> Range Extraction +Test for -> Range Extraction. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -27,13 +28,13 @@ @allure.link(url='https://www.codewars.com/kata/51ba717bb08c1cd60f00002f', name='Source/Kata') class SolutionTestCase(unittest.TestCase): - """ - Testing solution for Range Extraction problem - """ + """Testing solution for Range Extraction problem.""" def test_solution(self): """ - Testing solution function + Testing solution function. + + :return: """ allure.dynamic.title("Testing solution function") allure.dynamic.severity(allure.severity_level.NORMAL) From 5df87a08dc8cd44ac7bef51db4868fbe8df7a05c Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:44:22 -0800 Subject: [PATCH 35/50] Update test_solution.py --- kyu_4/range_extraction/test_solution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_4/range_extraction/test_solution.py b/kyu_4/range_extraction/test_solution.py index 504099ff5c7..1827b11888c 100644 --- a/kyu_4/range_extraction/test_solution.py +++ b/kyu_4/range_extraction/test_solution.py @@ -33,7 +33,7 @@ class SolutionTestCase(unittest.TestCase): def test_solution(self): """ Testing solution function. - + :return: """ allure.dynamic.title("Testing solution function") From 12a2a4621ed4919636778cb715c4035a3e61eb36 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:48:51 -0800 Subject: [PATCH 36/50] Update test_next_bigger.py --- .../test_next_bigger.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kyu_4/next_bigger_number_with_the_same_digits/test_next_bigger.py b/kyu_4/next_bigger_number_with_the_same_digits/test_next_bigger.py index 924c6be31c5..8f5e497334c 100644 --- a/kyu_4/next_bigger_number_with_the_same_digits/test_next_bigger.py +++ b/kyu_4/next_bigger_number_with_the_same_digits/test_next_bigger.py @@ -1,5 +1,6 @@ """ -Test for -> Next bigger number with the same digits +Test for -> Next bigger number with the same digits. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -29,12 +30,11 @@ name='Source/Kata') # pylint: enable-msg=R0801 class NextBiggerTestCase(unittest.TestCase): - """ - Testing next_bigger function - """ + """Testing next_bigger function.""" + def test_next_bigger(self): """ - Testing next_bigger function + Testing next_bigger function. You have to test a function that takes a positive integer number and returns the next bigger number formed by the same digits: @@ -43,7 +43,8 @@ def test_next_bigger(self): 513 ==> 531 2017 ==> 2071 - If no bigger number can be composed using those digits, return -1 + If no bigger number can be composed using those digits, return -1. + :return: """ # pylint: disable-msg=R0801 allure.dynamic.title("Testing next_bigger function") From b6f7688cb96c77ca2a505da43342cea4cf011ca7 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sat, 7 Dec 2024 05:48:55 -0800 Subject: [PATCH 37/50] Update next_bigger.py --- .../next_bigger.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py b/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py index bd50df22896..ecf954949fe 100644 --- a/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py +++ b/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py @@ -8,10 +8,14 @@ def next_bigger(n: int) -> int: """ + Next bigger function. + A function that takes a positive integer number and returns the next bigger number formed by the same digits. - If no bigger number can be composed using those digits, return -1 + If no bigger number can be composed using those digits, return -1. + :param n: + :return: """ # 1. Starting from last digit of given number, find the first digit # which breaks the sorted ordering. Let the index of this found @@ -33,6 +37,8 @@ def next_bigger(n: int) -> int: def digit_that_breaks_ordering_index(digits: list) -> int: """ + Finds a digit that breaks ordering index. + Starting from last digit of given number, find the first digit which breaks the sorted ordering. Let the index of this found digit be 'i' and the digit be number[i]. @@ -49,6 +55,8 @@ def digit_that_breaks_ordering_index(digits: list) -> int: def next_greater_digit_index(digits: list, i: int) -> int: """ + Find next greater digit index. + Find the next greater digit in the right portion of number[i] - that is from digit at index i+1 to last digit. Let that digit be number[j] at index 'j'. From 458008075b9606ab82276f094b845359ec8d7c7a Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 04:43:26 -0800 Subject: [PATCH 38/50] Update next_bigger.py kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py:39 in public function `digit_that_breaks_ordering_index`: D401: First line should be in imperative mood (perhaps 'Find', not 'Finds') [Docstring] prescribes the function or method's effect as a command: ("Do this", "Return that"), not as a description; e.g. don't write "Returns the pathname ...". --- kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py b/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py index ecf954949fe..1dda31b556f 100644 --- a/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py +++ b/kyu_4/next_bigger_number_with_the_same_digits/next_bigger.py @@ -37,7 +37,7 @@ def next_bigger(n: int) -> int: def digit_that_breaks_ordering_index(digits: list) -> int: """ - Finds a digit that breaks ordering index. + Find a digit that breaks ordering index. Starting from last digit of given number, find the first digit which breaks the sorted ordering. Let the index of From 56f775502700d4a09eaa718cd01449707d572e6f Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 04:47:26 -0800 Subject: [PATCH 39/50] Update test_warrior.py --- kyu_4/the_greatest_warrior/test_warrior.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kyu_4/the_greatest_warrior/test_warrior.py b/kyu_4/the_greatest_warrior/test_warrior.py index c4256f1c0b0..73d0eb446ca 100644 --- a/kyu_4/the_greatest_warrior/test_warrior.py +++ b/kyu_4/the_greatest_warrior/test_warrior.py @@ -1,5 +1,6 @@ """ -Test for -> The Greatest Warrior -> test warrior +Test for -> The Greatest Warrior -> test warrior. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -31,13 +32,13 @@ name='Source/Kata') # pylint: enable-msg=R0801 class WarriorTestCase(unittest.TestCase): - """ - Testing Warrior class - """ + """Testing Warrior class.""" def test_warrior_tom(self): """ - Testing Warrior class >>> tom + Testing Warrior class >>> tom. + + :return: """ # pylint: disable=R0801 allure.dynamic.title("Testing Warrior class >>> tom") @@ -66,7 +67,9 @@ def test_warrior_tom(self): def test_warrior_bruce_lee(self): """ - Testing Warrior class >>> bruce_lee + Testing Warrior class >>> bruce_lee. + + :return: """ # pylint: disable=R0801 allure.dynamic.title("Testing Warrior class >>> bruce_lee") From 25323b56ed778bec2b22b4dc036f5547a8877079 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 04:47:29 -0800 Subject: [PATCH 40/50] Update warrior.py --- kyu_4/the_greatest_warrior/warrior.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kyu_4/the_greatest_warrior/warrior.py b/kyu_4/the_greatest_warrior/warrior.py index f225b1c8666..50f9af9e7b2 100644 --- a/kyu_4/the_greatest_warrior/warrior.py +++ b/kyu_4/the_greatest_warrior/warrior.py @@ -1,5 +1,6 @@ """ -Solution for -> The Greatest Warrior +Solution for -> The Greatest Warrior. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -89,7 +90,8 @@ def __update_experience(self, experience: int): @property def level(self) -> int: """ - A warrior's level + A warrior's level. + :return: A warrior's level """ return self.__level @@ -98,7 +100,8 @@ def level(self) -> int: def rank(self) -> str: """ A warrior starts at rank "Pushover" and - can progress all the way to "Greatest" + can progress all the way to "Greatest". + :return: warrior's rank """ return self.__rank @@ -106,7 +109,8 @@ def rank(self) -> str: @property def experience(self) -> int: """ - Return experience value + Return experience value. + :return: """ return self.__experience @@ -121,7 +125,8 @@ def achievements(self) -> list: def battle(self, enemy_level: int) -> str: """ - Return message based on the result of the battle + Return message based on the result of the battle. + :param enemy_level: :return: """ From f38677dca63adab82b3a6462dfc7fc6605ea10a3 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 04:49:07 -0800 Subject: [PATCH 41/50] Update warrior.py --- kyu_4/the_greatest_warrior/warrior.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/kyu_4/the_greatest_warrior/warrior.py b/kyu_4/the_greatest_warrior/warrior.py index 50f9af9e7b2..cc2ffca4546 100644 --- a/kyu_4/the_greatest_warrior/warrior.py +++ b/kyu_4/the_greatest_warrior/warrior.py @@ -48,12 +48,16 @@ def __init__(self): def __set_rank(self) -> str: """ + Set rank. + :return: warrior's experience """ return RANKS[(self.level // 10)] def __set_level(self) -> int: """ + Set level. + A warrior starts at level 1 and can progress all the way to 100. @@ -70,13 +74,14 @@ def __set_level(self) -> int: def __update_experience(self, experience: int): """ + Update expirience. + A warrior's experience is cumulative, and does not reset with each rise of level. The only exception is when the warrior reaches level 100, with which the experience stops at 10000. :return: """ - if self.level == 100: self.__experience = MAX_EXPERIENCE elif self.experience + experience > MAX_EXPERIENCE: @@ -99,6 +104,8 @@ def level(self) -> int: @property def rank(self) -> str: """ + Rank. + A warrior starts at rank "Pushover" and can progress all the way to "Greatest". @@ -118,7 +125,8 @@ def experience(self) -> int: @property def achievements(self) -> list: """ - Return achievements as a list + Return achievements as a list. + :return: """ return self.__achievements @@ -126,7 +134,7 @@ def achievements(self) -> list: def battle(self, enemy_level: int) -> str: """ Return message based on the result of the battle. - + :param enemy_level: :return: """ From 477071481c15866708f692d4a481c9f071a09c17 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 04:58:37 -0800 Subject: [PATCH 42/50] Update warrior.py --- kyu_4/the_greatest_warrior/warrior.py | 32 ++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/kyu_4/the_greatest_warrior/warrior.py b/kyu_4/the_greatest_warrior/warrior.py index cc2ffca4546..113b2294067 100644 --- a/kyu_4/the_greatest_warrior/warrior.py +++ b/kyu_4/the_greatest_warrior/warrior.py @@ -37,6 +37,7 @@ class Warrior: """ def __init__(self): + """Create a new warrior instance.""" # A warrior's experience starts from 100 self.__experience = BASIC_EXPERIENCE # A warrior starts at level 1 @@ -67,14 +68,14 @@ def __set_level(self) -> int: by another 100, the warrior's level rises to the next level. - :return: + :return: int """ new_level = self.experience // BASIC_EXPERIENCE return new_level if new_level <= 100 else 100 - def __update_experience(self, experience: int): + def __update_experience(self, experience: int) -> None: """ - Update expirience. + Update experience. A warrior's experience is cumulative, and does not reset with each rise of level. The only exception @@ -82,9 +83,8 @@ def __update_experience(self, experience: int): the experience stops at 10000. :return: """ - if self.level == 100: - self.__experience = MAX_EXPERIENCE - elif self.experience + experience > MAX_EXPERIENCE: + if (self.level == 100 + or self.experience + experience > MAX_EXPERIENCE): self.__experience = MAX_EXPERIENCE else: self.__experience += experience @@ -118,7 +118,7 @@ def experience(self) -> int: """ Return experience value. - :return: + :return: int """ return self.__experience @@ -127,7 +127,7 @@ def achievements(self) -> list: """ Return achievements as a list. - :return: + :return: list """ return self.__achievements @@ -135,8 +135,8 @@ def battle(self, enemy_level: int) -> str: """ Return message based on the result of the battle. - :param enemy_level: - :return: + :param enemy_level: int + :return: str """ msg: str = '' # If an enemy level does not fall in the range of 1 to 100, @@ -174,13 +174,15 @@ def battle(self, enemy_level: int) -> str: def training(self, params: list) -> str: """ + Training method. + Training will accept an array of three elements: - the description, - the experience points your warrior earns, - and the minimum level requirement. + 1. the description. + 2. the experience points your warrior earns. + 3. the minimum level requirement. - :param params: - :return: + :param params: list + :return: str """ # If the warrior's level meets the minimum level requirement, # the warrior will receive the experience points from it and From 373599888c69c1c00ba02896ae220ac29be8fb8e Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 05:00:08 -0800 Subject: [PATCH 43/50] Update warrior.py --- kyu_4/the_greatest_warrior/warrior.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kyu_4/the_greatest_warrior/warrior.py b/kyu_4/the_greatest_warrior/warrior.py index 113b2294067..8189a410d56 100644 --- a/kyu_4/the_greatest_warrior/warrior.py +++ b/kyu_4/the_greatest_warrior/warrior.py @@ -32,6 +32,8 @@ class Warrior: """ + Warrior class. + A class called Warrior which calculates and keeps track of level and skills, and ranks. """ From 97c69d8bd45140d32bc1c4d0ebf0032f09db53d0 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 05:01:35 -0800 Subject: [PATCH 44/50] Update test_sum_for_list.py --- kyu_4/sum_by_factors/test_sum_for_list.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kyu_4/sum_by_factors/test_sum_for_list.py b/kyu_4/sum_by_factors/test_sum_for_list.py index ca05d5c0615..7083f723ee3 100644 --- a/kyu_4/sum_by_factors/test_sum_for_list.py +++ b/kyu_4/sum_by_factors/test_sum_for_list.py @@ -1,5 +1,6 @@ """ -Testing sum_for_list function +Testing sum_for_list function. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -25,13 +26,12 @@ url='https://www.codewars.com/kata/54d496788776e49e6b00052f', name='Source/Kata') class SumForListTestCase(unittest.TestCase): - """ - Testing sum_for_list function - """ + """Testing sum_for_list function.""" def test_sum_for_list(self): """ - Testing sum_for_list function + Testing sum_for_list function. + :return: """ # pylint: disable-msg=R0801 From 9a5a83602b5b698c5e733453bb83284a2502b7fb Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 05:01:53 -0800 Subject: [PATCH 45/50] Update test_sum_for_list.py --- kyu_4/sum_by_factors/test_sum_for_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_4/sum_by_factors/test_sum_for_list.py b/kyu_4/sum_by_factors/test_sum_for_list.py index 7083f723ee3..bd31fdc46dd 100644 --- a/kyu_4/sum_by_factors/test_sum_for_list.py +++ b/kyu_4/sum_by_factors/test_sum_for_list.py @@ -31,7 +31,7 @@ class SumForListTestCase(unittest.TestCase): def test_sum_for_list(self): """ Testing sum_for_list function. - + :return: """ # pylint: disable-msg=R0801 From 0d2b08c522230c782758781370195bc3272500a2 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 05:06:29 -0800 Subject: [PATCH 46/50] Update format_duration.py --- .../format_duration.py | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/kyu_4/human_readable_duration_format/format_duration.py b/kyu_4/human_readable_duration_format/format_duration.py index 4706fb41930..c1c41e583de 100644 --- a/kyu_4/human_readable_duration_format/format_duration.py +++ b/kyu_4/human_readable_duration_format/format_duration.py @@ -14,35 +14,9 @@ def format_duration(seconds: int) -> str: A function which formats a duration, given as a number of seconds, in a human-friendly way. - - The resulting expression is made of components like 4 seconds, - 1 year, etc. In general, a positive integer and one of the - valid units of time, separated by a space. The unit of time - is used in plural if the integer is greater than 1. - - The components are separated by a comma and a space (", "). - Except the last component, which is separated by " and ", just - like it would be written in English. - - A more significant units of time will occur before than a least - significant one. Therefore, 1 second and 1 year is not correct, - but 1 year and 1 second is. - - Different components have different unit of times. So there is - not repeated units like in 5 seconds and 1 second. - - A component will not appear at all if its value happens to be zero. - Hence, 1 minute and 0 seconds is not valid, but it should be just 1 minute. - - A unit of time must be used "as much as possible". It means that the - function should not return 61 seconds, but 1 minute and 1 second instead. - Formally, the duration specified by of a component must not be greater than - any valid more significant unit of time. - :param seconds: int :return: str """ - if seconds == 0: return 'now' From 25af3b2ae85e63c539606d65c6fe6eed911aa9b3 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 05:09:30 -0800 Subject: [PATCH 47/50] Update valid_solution.py --- kyu_4/sudoku_solution_validator/valid_solution.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kyu_4/sudoku_solution_validator/valid_solution.py b/kyu_4/sudoku_solution_validator/valid_solution.py index 84e02f9ff21..3245ade835d 100644 --- a/kyu_4/sudoku_solution_validator/valid_solution.py +++ b/kyu_4/sudoku_solution_validator/valid_solution.py @@ -8,11 +8,13 @@ def valid_solution(board: list) -> bool: """ + Sudoku solution validator. + A function validSolution/ValidateSolution/valid_solution() that accepts a 2D array representing a Sudoku board, - and returns true if it is a valid solution, or false otherwise - :param board: - :return: + and returns true if it is a valid solution, or false otherwise. + :param board: list + :return: bool """ return all([check_horizontally(board), check_vertically(board), @@ -40,7 +42,6 @@ def check_vertically(board: list) -> bool: :return: """ i: int = 0 - while i < 9: col: list = [] for row in board: @@ -56,8 +57,8 @@ def check_sub_grids(board: list) -> bool: Test each of the nine 3x3 sub-grids. (also known as blocks) - :param board: - :return: + :param board: list + :return: bool """ sub_grids: list = [ board[0][:3] + board[1][:3] + board[2][:3], From e53e400622a5788e796805d454f351d0b6844a33 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 05:10:34 -0800 Subject: [PATCH 48/50] Update valid_solution.py --- kyu_4/sudoku_solution_validator/valid_solution.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kyu_4/sudoku_solution_validator/valid_solution.py b/kyu_4/sudoku_solution_validator/valid_solution.py index 3245ade835d..e4c27c50b56 100644 --- a/kyu_4/sudoku_solution_validator/valid_solution.py +++ b/kyu_4/sudoku_solution_validator/valid_solution.py @@ -10,8 +10,7 @@ def valid_solution(board: list) -> bool: """ Sudoku solution validator. - A function validSolution/ValidateSolution/valid_solution() - that accepts a 2D array representing a Sudoku board, + A function that accepts a 2D array representing a Sudoku board, and returns true if it is a valid solution, or false otherwise. :param board: list :return: bool From 5f996168716443a040ea83f369ea13166005c92f Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 05:11:55 -0800 Subject: [PATCH 49/50] Update sum_of_intervals.py --- kyu_4/sum_of_intervals/sum_of_intervals.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kyu_4/sum_of_intervals/sum_of_intervals.py b/kyu_4/sum_of_intervals/sum_of_intervals.py index 444bc889d34..23b425ca703 100644 --- a/kyu_4/sum_of_intervals/sum_of_intervals.py +++ b/kyu_4/sum_of_intervals/sum_of_intervals.py @@ -8,9 +8,10 @@ def sum_of_intervals(intervals: list) -> int: """ - Accepts an array of intervals, and returns - the sum of all the interval lengths. + Sum of intervals. + Accept an array of intervals, and returns + the sum of all the interval lengths. Overlapping intervals should only be counted once. :param intervals: list :return: int From fc29afe78004911f8e98c1f84631dbf8aee32f2a Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Sun, 8 Dec 2024 05:13:28 -0800 Subject: [PATCH 50/50] Update sum_of_intervals.py --- kyu_4/sum_of_intervals/sum_of_intervals.py | 1 - 1 file changed, 1 deletion(-) diff --git a/kyu_4/sum_of_intervals/sum_of_intervals.py b/kyu_4/sum_of_intervals/sum_of_intervals.py index 23b425ca703..25693462476 100644 --- a/kyu_4/sum_of_intervals/sum_of_intervals.py +++ b/kyu_4/sum_of_intervals/sum_of_intervals.py @@ -16,7 +16,6 @@ def sum_of_intervals(intervals: list) -> int: :param intervals: list :return: int """ - intervals = remove_overlaps(intervals) results: list = [(i[1] - i[0]) for i in intervals] return sum(results)