From 4e9df4a06fa70843867faac49cbe9e8f2d8d83eb Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:12:28 +0530 Subject: [PATCH 01/22] Fix: Issue 9588 --- maths/base_neg2_conversion.py | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 maths/base_neg2_conversion.py diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py new file mode 100644 index 000000000000..f06c639ac291 --- /dev/null +++ b/maths/base_neg2_conversion.py @@ -0,0 +1,37 @@ +import doctest +def decimal_to_negative_base_2(n): + """ + This function returns the number negative base 2 of the decimal number of the input data. + + Args: + n (int): The decimal number to convert. + + Returns: + int: The negative base 2 number. + + Examples: + >>> decimal_to_negative_base_2(0) + 0 + >>> decimal_to_negative_base_2(-19) + 111101 + >>> decimal_to_negative_base_2(4) + 100 + >>> decimal_to_negative_base_2(7) + 11011 + """ + if n == 0: + return 0 + ans = "" + while n != 0: + rem = n % -2 + n = n // -2 + if rem < 0: + rem += 2 + n += 1 + + ans = str(rem) + ans + + return int(ans) + +if __name__ == "__main__": + doctest.testmod() From 1fab3027ccbf98562ae04c2ea4a95559bb01c2ae Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:13:13 +0530 Subject: [PATCH 02/22] Fix: Issue 9588 --- maths/base_neg2_conversion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index f06c639ac291..e57942ba01db 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -4,7 +4,7 @@ def decimal_to_negative_base_2(n): This function returns the number negative base 2 of the decimal number of the input data. Args: - n (int): The decimal number to convert. + int: The decimal number to convert. Returns: int: The negative base 2 number. From 143764d456c9a018b9fd3570a1d504ea42fe2b37 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:49:29 +0000 Subject: [PATCH 03/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/base_neg2_conversion.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index e57942ba01db..55d0416bcb8f 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -1,4 +1,6 @@ import doctest + + def decimal_to_negative_base_2(n): """ This function returns the number negative base 2 of the decimal number of the input data. @@ -33,5 +35,6 @@ def decimal_to_negative_base_2(n): return int(ans) + if __name__ == "__main__": doctest.testmod() From 045652d3eaefd00aee1b3f146b657014f4f6c498 Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:37:58 +0530 Subject: [PATCH 04/22] Fix: Issue 9588 --- maths/base_neg2_conversion.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index e57942ba01db..3bdcf91abe1b 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -1,7 +1,8 @@ import doctest -def decimal_to_negative_base_2(n): +def decimal_to_negative_base_2(n: int) -> int: """ - This function returns the number negative base 2 of the decimal number of the input data. + This function returns the number negative base 2 + of the decimal number of the input data. Args: int: The decimal number to convert. From 95161a0f6fe9f095b3d79ac70ea55a2abbfa13b5 Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:41:27 +0530 Subject: [PATCH 05/22] Fix: Issue #9588 --- maths/base_neg2_conversion.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index 1693852ca597..3bdcf91abe1b 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -1,5 +1,5 @@ import doctest -def decimal_to_negative_base_2(n): +def decimal_to_negative_base_2(n: int) -> int: """ This function returns the number negative base 2 of the decimal number of the input data. @@ -34,6 +34,5 @@ def decimal_to_negative_base_2(n): return int(ans) - if __name__ == "__main__": doctest.testmod() From 155601c61d9963ac4635fc88df05c93b15bf4fa6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 19:12:43 +0000 Subject: [PATCH 06/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/base_neg2_conversion.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index 3bdcf91abe1b..8c86c22eaf29 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -1,7 +1,9 @@ import doctest + + def decimal_to_negative_base_2(n: int) -> int: """ - This function returns the number negative base 2 + This function returns the number negative base 2 of the decimal number of the input data. Args: @@ -34,5 +36,6 @@ def decimal_to_negative_base_2(n: int) -> int: return int(ans) + if __name__ == "__main__": doctest.testmod() From 376cb60519cad5f39e9d710df940677434972d62 Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:49:09 +0530 Subject: [PATCH 07/22] Fix: Issue #9588 --- maths/base_neg2_conversion.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index 3bdcf91abe1b..56ce246d8c6d 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -1,5 +1,5 @@ import doctest -def decimal_to_negative_base_2(n: int) -> int: +def decimal_to_negative_base_2(num: int) -> int: """ This function returns the number negative base 2 of the decimal number of the input data. @@ -20,15 +20,15 @@ def decimal_to_negative_base_2(n: int) -> int: >>> decimal_to_negative_base_2(7) 11011 """ - if n == 0: + if num == 0: return 0 ans = "" - while n != 0: - rem = n % -2 - n = n // -2 + while num != 0: + rem = num % -2 + num = num // -2 if rem < 0: rem += 2 - n += 1 + num += 1 ans = str(rem) + ans From a878e4ba71bc421437060f06e7eb9dc45eead74a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 19:21:07 +0000 Subject: [PATCH 08/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/base_neg2_conversion.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index 6077d1dbe90e..b2d98536b5e3 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -1,4 +1,6 @@ import doctest + + def decimal_to_negative_base_2(num: int) -> int: """ This function returns the number negative base 2 From 115703ebc755c8b35e14acc1a97224ee757b1d74 Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Thu, 5 Oct 2023 10:41:41 +0530 Subject: [PATCH 09/22] Fix: Issue #9588 --- maths/base_neg2_conversion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index 6077d1dbe90e..432c74d5c064 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -1,8 +1,7 @@ -import doctest def decimal_to_negative_base_2(num: int) -> int: """ This function returns the number negative base 2 - of the decimal number of the input data. + of the decimal number of the input data. Args: int: The decimal number to convert. @@ -36,4 +35,5 @@ def decimal_to_negative_base_2(num: int) -> int: if __name__ == "__main__": + import doctest doctest.testmod() From 23ef488cbd3794c363a7efe77b225adb4d7dcf84 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 05:12:59 +0000 Subject: [PATCH 10/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/base_neg2_conversion.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index 432c74d5c064..f9c8a7f24707 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -36,4 +36,5 @@ def decimal_to_negative_base_2(num: int) -> int: if __name__ == "__main__": import doctest + doctest.testmod() From 6b474217bac391745a17b346e1ca1061ab92068b Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:31:08 +0530 Subject: [PATCH 11/22] fix: issue #9793 --- .../activation_functions}/sigmoid_linear_unit.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {maths => neural_network/activation_functions}/sigmoid_linear_unit.py (100%) diff --git a/maths/sigmoid_linear_unit.py b/neural_network/activation_functions/sigmoid_linear_unit.py similarity index 100% rename from maths/sigmoid_linear_unit.py rename to neural_network/activation_functions/sigmoid_linear_unit.py From e7bc55ce6dd7a75fb693a9d01d09c86813714cc0 Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:39:12 +0530 Subject: [PATCH 12/22] fix: issue #9793 --- maths/base_neg2_conversion.py | 8 ++------ .../activation_functions => maths}/sigmoid_linear_unit.py | 0 2 files changed, 2 insertions(+), 6 deletions(-) rename {neural_network/activation_functions => maths}/sigmoid_linear_unit.py (100%) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index f9c8a7f24707..bb1f756432cd 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -23,18 +23,14 @@ def decimal_to_negative_base_2(num: int) -> int: return 0 ans = "" while num != 0: - rem = num % -2 - num = num // -2 + num,rem =divmod(num, -2) if rem < 0: rem += 2 num += 1 - ans = str(rem) + ans - return int(ans) if __name__ == "__main__": import doctest - - doctest.testmod() + doctest.testmod() \ No newline at end of file diff --git a/neural_network/activation_functions/sigmoid_linear_unit.py b/maths/sigmoid_linear_unit.py similarity index 100% rename from neural_network/activation_functions/sigmoid_linear_unit.py rename to maths/sigmoid_linear_unit.py From 8606171745e62dcbb9ce74bd55bbb1cdd17676b7 Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:42:01 +0530 Subject: [PATCH 13/22] fix: issue #9588 --- maths/base_neg2_conversion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index bb1f756432cd..35c74b2de121 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -33,4 +33,4 @@ def decimal_to_negative_base_2(num: int) -> int: if __name__ == "__main__": import doctest - doctest.testmod() \ No newline at end of file + doctest.testmod() From f521847472d001e79ca804cf946fbe36030ea999 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:13:27 +0000 Subject: [PATCH 14/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/base_neg2_conversion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maths/base_neg2_conversion.py b/maths/base_neg2_conversion.py index 35c74b2de121..81d40d37e79d 100644 --- a/maths/base_neg2_conversion.py +++ b/maths/base_neg2_conversion.py @@ -23,7 +23,7 @@ def decimal_to_negative_base_2(num: int) -> int: return 0 ans = "" while num != 0: - num,rem =divmod(num, -2) + num, rem = divmod(num, -2) if rem < 0: rem += 2 num += 1 @@ -33,4 +33,5 @@ def decimal_to_negative_base_2(num: int) -> int: if __name__ == "__main__": import doctest + doctest.testmod() From 5442a69bae2dc9865036aa077944f5b3698c6ef4 Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:58:52 +0530 Subject: [PATCH 15/22] fix: issue #9844 --- backtracking/match_word_pattern.py | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 backtracking/match_word_pattern.py diff --git a/backtracking/match_word_pattern.py b/backtracking/match_word_pattern.py new file mode 100644 index 000000000000..f0399ae55118 --- /dev/null +++ b/backtracking/match_word_pattern.py @@ -0,0 +1,54 @@ +def matchWordPattern(pattern :str, input_string: str) -> bool: + """ + Determine if a given pattern matches a string using backtracking. + + pattern: The pattern to match. + input_string: The string to match against the pattern. + return: True if the pattern matches the string, False otherwise. + + >>> matchWordPattern("aba", "GraphTreesGraph") + True + + >>> matchWordPattern("xyx", "PythonRubyPython") + True + + >>> matchWordPattern("GG", "PythonJavaPython") + False + """ + def backtrack(pattern_index, str_index): + if pattern_index == len(pattern) and str_index == len(input_string): + return True + if pattern_index == len(pattern) or str_index == len(input_string): + return False + + char = pattern[pattern_index] + + if char in pattern_map: + mapped_str = pattern_map[char] + if input_string.startswith(mapped_str, str_index): + return backtrack(pattern_index + 1, str_index + len(mapped_str)) + else: + return False + + for end in range(str_index + 1, len(input_string) + 1): + substr = input_string[str_index:end] + if substr in str_map: + continue + + pattern_map[char] = substr + str_map[substr] = char + + if backtrack(pattern_index + 1, end): + return True + + del pattern_map[char] + del str_map[substr] + return False + + pattern_map = {} + str_map = {} + return backtrack(0, 0) + +if __name__ == "__main__": + import doctest + doctest.testmod() From 4f0baa21986c351264db21b7a0d565d877d90073 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:34:35 +0000 Subject: [PATCH 16/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- backtracking/match_word_pattern.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/backtracking/match_word_pattern.py b/backtracking/match_word_pattern.py index f0399ae55118..5132f58525ca 100644 --- a/backtracking/match_word_pattern.py +++ b/backtracking/match_word_pattern.py @@ -1,4 +1,4 @@ -def matchWordPattern(pattern :str, input_string: str) -> bool: +def matchWordPattern(pattern: str, input_string: str) -> bool: """ Determine if a given pattern matches a string using backtracking. @@ -15,40 +15,43 @@ def matchWordPattern(pattern :str, input_string: str) -> bool: >>> matchWordPattern("GG", "PythonJavaPython") False """ + def backtrack(pattern_index, str_index): if pattern_index == len(pattern) and str_index == len(input_string): return True if pattern_index == len(pattern) or str_index == len(input_string): return False - + char = pattern[pattern_index] - + if char in pattern_map: mapped_str = pattern_map[char] if input_string.startswith(mapped_str, str_index): return backtrack(pattern_index + 1, str_index + len(mapped_str)) else: return False - + for end in range(str_index + 1, len(input_string) + 1): substr = input_string[str_index:end] if substr in str_map: continue - + pattern_map[char] = substr str_map[substr] = char - + if backtrack(pattern_index + 1, end): return True - + del pattern_map[char] del str_map[substr] return False - + pattern_map = {} str_map = {} return backtrack(0, 0) + if __name__ == "__main__": import doctest + doctest.testmod() From c1680baee148748a0410552d90b7705e29ff1a03 Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:05:28 +0530 Subject: [PATCH 17/22] fix: issue #9844 --- backtracking/match_word_pattern.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/backtracking/match_word_pattern.py b/backtracking/match_word_pattern.py index f0399ae55118..257d18bf6c42 100644 --- a/backtracking/match_word_pattern.py +++ b/backtracking/match_word_pattern.py @@ -1,4 +1,4 @@ -def matchWordPattern(pattern :str, input_string: str) -> bool: +def match_word_pattern(pattern :str, input_string: str) -> bool: """ Determine if a given pattern matches a string using backtracking. @@ -6,13 +6,13 @@ def matchWordPattern(pattern :str, input_string: str) -> bool: input_string: The string to match against the pattern. return: True if the pattern matches the string, False otherwise. - >>> matchWordPattern("aba", "GraphTreesGraph") + >>> match_word_pattern("aba", "GraphTreesGraph") True - >>> matchWordPattern("xyx", "PythonRubyPython") + >>> match_word_pattern("xyx", "PythonRubyPython") True - >>> matchWordPattern("GG", "PythonJavaPython") + >>> match_word_pattern("GG", "PythonJavaPython") False """ def backtrack(pattern_index, str_index): @@ -20,31 +20,24 @@ def backtrack(pattern_index, str_index): return True if pattern_index == len(pattern) or str_index == len(input_string): return False - char = pattern[pattern_index] - if char in pattern_map: mapped_str = pattern_map[char] if input_string.startswith(mapped_str, str_index): return backtrack(pattern_index + 1, str_index + len(mapped_str)) else: return False - for end in range(str_index + 1, len(input_string) + 1): substr = input_string[str_index:end] if substr in str_map: continue - pattern_map[char] = substr str_map[substr] = char - if backtrack(pattern_index + 1, end): return True - del pattern_map[char] del str_map[substr] return False - pattern_map = {} str_map = {} return backtrack(0, 0) From 7c9c36e4886d2ef1788b6e0a968f256601684ed2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:38:36 +0000 Subject: [PATCH 18/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- backtracking/match_word_pattern.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backtracking/match_word_pattern.py b/backtracking/match_word_pattern.py index 257d18bf6c42..63c8af24fe0d 100644 --- a/backtracking/match_word_pattern.py +++ b/backtracking/match_word_pattern.py @@ -1,4 +1,4 @@ -def match_word_pattern(pattern :str, input_string: str) -> bool: +def match_word_pattern(pattern: str, input_string: str) -> bool: """ Determine if a given pattern matches a string using backtracking. @@ -15,6 +15,7 @@ def match_word_pattern(pattern :str, input_string: str) -> bool: >>> match_word_pattern("GG", "PythonJavaPython") False """ + def backtrack(pattern_index, str_index): if pattern_index == len(pattern) and str_index == len(input_string): return True @@ -38,10 +39,13 @@ def backtrack(pattern_index, str_index): del pattern_map[char] del str_map[substr] return False + pattern_map = {} str_map = {} return backtrack(0, 0) + if __name__ == "__main__": import doctest + doctest.testmod() From e3a45ebebd8187d6c55021ee61f18eb7585df82a Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:15:37 +0530 Subject: [PATCH 19/22] fix: issue #9844 --- backtracking/match_word_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backtracking/match_word_pattern.py b/backtracking/match_word_pattern.py index 257d18bf6c42..79a59a312302 100644 --- a/backtracking/match_word_pattern.py +++ b/backtracking/match_word_pattern.py @@ -38,8 +38,8 @@ def backtrack(pattern_index, str_index): del pattern_map[char] del str_map[substr] return False - pattern_map = {} - str_map = {} + pattern_map: dict[str,str] = {} + str_map: dict[str,str] = {} return backtrack(0, 0) if __name__ == "__main__": From c4fa0e17731254ad19b971085622a80b18c451dc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:49:12 +0000 Subject: [PATCH 20/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- backtracking/match_word_pattern.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backtracking/match_word_pattern.py b/backtracking/match_word_pattern.py index 1366571da4df..a1c9f7f8d5e3 100644 --- a/backtracking/match_word_pattern.py +++ b/backtracking/match_word_pattern.py @@ -39,8 +39,9 @@ def backtrack(pattern_index, str_index): del pattern_map[char] del str_map[substr] return False - pattern_map: dict[str,str] = {} - str_map: dict[str,str] = {} + + pattern_map: dict[str, str] = {} + str_map: dict[str, str] = {} return backtrack(0, 0) From 26e33d817d4da3f17cec02988de1aa256b94d35e Mon Sep 17 00:00:00 2001 From: Abul Hasan <33129246+haxkd@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:23:48 +0530 Subject: [PATCH 21/22] fix: issue #9844 --- backtracking/match_word_pattern.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/backtracking/match_word_pattern.py b/backtracking/match_word_pattern.py index a1c9f7f8d5e3..f0bafb85a2b3 100644 --- a/backtracking/match_word_pattern.py +++ b/backtracking/match_word_pattern.py @@ -16,7 +16,17 @@ def match_word_pattern(pattern: str, input_string: str) -> bool: False """ - def backtrack(pattern_index, str_index): + def backtrack(pattern_index: int, str_index: int) -> bool: + """ + >>> backtrack(0, 0) + True + + >>> backtrack(0, 1) + True + + >>> backtrack(0, 4) + False + """ if pattern_index == len(pattern) and str_index == len(input_string): return True if pattern_index == len(pattern) or str_index == len(input_string): @@ -39,7 +49,6 @@ def backtrack(pattern_index, str_index): del pattern_map[char] del str_map[substr] return False - pattern_map: dict[str, str] = {} str_map: dict[str, str] = {} return backtrack(0, 0) @@ -47,5 +56,4 @@ def backtrack(pattern_index, str_index): if __name__ == "__main__": import doctest - doctest.testmod() From 8df08a3566bf2d0c58fa2f53b36676c4b11ce3ef Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:56:40 +0000 Subject: [PATCH 22/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- backtracking/match_word_pattern.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backtracking/match_word_pattern.py b/backtracking/match_word_pattern.py index f0bafb85a2b3..bfa9b1354d51 100644 --- a/backtracking/match_word_pattern.py +++ b/backtracking/match_word_pattern.py @@ -49,6 +49,7 @@ def backtrack(pattern_index: int, str_index: int) -> bool: del pattern_map[char] del str_map[substr] return False + pattern_map: dict[str, str] = {} str_map: dict[str, str] = {} return backtrack(0, 0) @@ -56,4 +57,5 @@ def backtrack(pattern_index: int, str_index: int) -> bool: if __name__ == "__main__": import doctest + doctest.testmod()