Skip to content

Commit dcf88f8

Browse files
committed
2 parents 9dce568 + ce43a8a commit dcf88f8

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
- id: auto-walrus
1717

1818
- repo: https://github.com/charliermarsh/ruff-pre-commit
19-
rev: v0.0.267
19+
rev: v0.0.269
2020
hooks:
2121
- id: ruff
2222

@@ -46,7 +46,7 @@ repos:
4646
pass_filenames: false
4747

4848
- repo: https://github.com/abravalheri/validate-pyproject
49-
rev: v0.12.2
49+
rev: v0.13
5050
hooks:
5151
- id: validate-pyproject
5252

DIRECTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@
577577
* [Hexagonal Number](maths/hexagonal_number.py)
578578
* [Integration By Simpson Approx](maths/integration_by_simpson_approx.py)
579579
* [Is Ip V4 Address Valid](maths/is_ip_v4_address_valid.py)
580+
* [Is Palindrome](maths/is_palindrome.py)
580581
* [Is Square Free](maths/is_square_free.py)
581582
* [Jaccard Similarity](maths/jaccard_similarity.py)
582583
* [Juggler Sequence](maths/juggler_sequence.py)

ciphers/mixed_keyword_cypher.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ def mixed_keyword(key: str = "college", pt: str = "UNIVERSITY") -> str:
6565
return cypher
6666

6767

68-
print(mixed_keyword("college", "UNIVERSITY"))
68+
if __name__ == "__main__":
69+
print(mixed_keyword("college", "UNIVERSITY"))

maths/is_palindrome.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def is_palindrome(num: int) -> bool:
2+
"""
3+
Returns whether `num` is a palindrome or not
4+
(see for reference https://en.wikipedia.org/wiki/Palindromic_number).
5+
6+
>>> is_palindrome(-121)
7+
False
8+
>>> is_palindrome(0)
9+
True
10+
>>> is_palindrome(10)
11+
False
12+
>>> is_palindrome(11)
13+
True
14+
>>> is_palindrome(101)
15+
True
16+
>>> is_palindrome(120)
17+
False
18+
"""
19+
if num < 0:
20+
return False
21+
22+
num_copy: int = num
23+
rev_num: int = 0
24+
while num > 0:
25+
rev_num = rev_num * 10 + (num % 10)
26+
num //= 10
27+
28+
return num_copy == rev_num
29+
30+
31+
if __name__ == "__main__":
32+
import doctest
33+
34+
doctest.testmod()

0 commit comments

Comments
 (0)