Skip to content

Commit 6a57de7

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 566fa0e commit 6a57de7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

hashes/polynomial_hash.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
Returns: int: The computed hash value.
1010
Wikipedia :: https://en.wikipedia.org/wiki/Hash_function
1111
"""
12+
13+
1214
def polynomial_hash(s, p=31, m=10**9 + 9):
1315
hash_value = 0
1416
p_pow = 1
1517
for char in s:
16-
char_value = ord(char) - ord('a') + 1 # Convert character to a numerical value
18+
char_value = ord(char) - ord("a") + 1 # Convert character to a numerical value
1719
hash_value = (hash_value + char_value * p_pow) % m
1820
p_pow = (p_pow * p) % m
1921
return hash_value
2022

21-
print(polynomial_hash('PythonLanguage'))
23+
24+
print(polynomial_hash("PythonLanguage"))
2225
# Output: 877483825

0 commit comments

Comments
 (0)