Skip to content

Commit cfa099f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 9d6751c commit cfa099f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

strings/wildcard_pattern_matching_fft.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def preprocess_text_and_pattern(text: str, pattern: str) -> tuple[list[int], lis
2626

2727
return text_int, pattern_int
2828

29+
2930
def fft_convolution(first_seq: list[int], second_seq: list[int]) -> np.ndarray:
3031
"""Performs convolution using the Fast Fourier Transform (FFT).
3132
@@ -42,8 +43,6 @@ def fft_convolution(first_seq: list[int], second_seq: list[int]) -> np.ndarray:
4243
return np.real(ifft(first_seq_fft * second_seq_fft))
4344

4445

45-
46-
4746
def compute_a_fft(text_int: list[int], pattern_int: list[int]) -> np.ndarray:
4847
"""Computes the A array for the pattern matching algorithm.
4948
@@ -73,7 +72,7 @@ def compute_a_fft(text_int: list[int], pattern_int: list[int]) -> np.ndarray:
7372
sum3 = fft_convolution(p1[::-1], t3)
7473

7574
# Calculate a[i] using the convolution results
76-
a = sum1[:n - m + 1] - 2 * sum2[:n - m + 1] + sum3[:n - m + 1]
75+
a = sum1[: n - m + 1] - 2 * sum2[: n - m + 1] + sum3[: n - m + 1]
7776
# Calculate A[i] using the convolution results
7877
A = sum1[: n - m + 1] - 2 * sum2[: n - m + 1] + sum3[: n - m + 1]
7978

@@ -84,12 +83,12 @@ def compute_a_fft(text_int: list[int], pattern_int: list[int]) -> np.ndarray:
8483
if __name__ == "__main__":
8584
# Example test case
8685
import doctest
86+
8787
doctest.testmod()
8888
# Get text and pattern as input from the user
8989
# text = input("Enter the text: ")
9090
# pattern = input("Enter the pattern (use '*' for wildcard): ")
9191

92-
9392
text = "abcabc"
9493
pattern = "abc*"
9594

0 commit comments

Comments
 (0)