Skip to content

Commit d784b79

Browse files
authored
Merge branch 'TheAlgorithms:master' into algo/transitiveClosure
2 parents 0375f1b + 8f1a6b0 commit d784b79

File tree

6 files changed

+58
-6
lines changed

6 files changed

+58
-6
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
with:
1515
enable-cache: true
1616
cache-dependency-glob: uv.lock
17-
- uses: actions/setup-python@v5
17+
- uses: actions/setup-python@v6
1818
with:
1919
python-version: 3.x
2020
allow-prereleases: true

.github/workflows/directory_writer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- uses: actions/checkout@v5
1010
with:
1111
fetch-depth: 0
12-
- uses: actions/setup-python@v5
12+
- uses: actions/setup-python@v6
1313
with:
1414
python-version: 3.x
1515
- name: Write DIRECTORY.md

.github/workflows/project_euler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v5
1818
- uses: astral-sh/setup-uv@v6
19-
- uses: actions/setup-python@v5
19+
- uses: actions/setup-python@v6
2020
with:
2121
python-version: 3.x
2222
- run: uv sync --group=euler-validate --group=test
@@ -26,7 +26,7 @@ jobs:
2626
steps:
2727
- uses: actions/checkout@v5
2828
- uses: astral-sh/setup-uv@v6
29-
- uses: actions/setup-python@v5
29+
- uses: actions/setup-python@v6
3030
with:
3131
python-version: 3.x
3232
- run: uv sync --group=euler-validate --group=test

.github/workflows/sphinx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
steps:
2828
- uses: actions/checkout@v5
2929
- uses: astral-sh/setup-uv@v6
30-
- uses: actions/setup-python@v5
30+
- uses: actions/setup-python@v6
3131
with:
3232
python-version: 3.13
3333
allow-prereleases: true

maths/special_numbers/proth_number.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,50 @@ def proth(number: int) -> int:
5959
return proth_list[number - 1]
6060

6161

62+
def is_proth_number(number: int) -> bool:
63+
"""
64+
:param number: positive integer number
65+
:return: true if number is a Proth number, false otherwise
66+
>>> is_proth_number(1)
67+
False
68+
>>> is_proth_number(2)
69+
False
70+
>>> is_proth_number(3)
71+
True
72+
>>> is_proth_number(4)
73+
False
74+
>>> is_proth_number(5)
75+
True
76+
>>> is_proth_number(34)
77+
False
78+
>>> is_proth_number(-1)
79+
Traceback (most recent call last):
80+
...
81+
ValueError: Input value of [number=-1] must be > 0
82+
>>> is_proth_number(6.0)
83+
Traceback (most recent call last):
84+
...
85+
TypeError: Input value of [number=6.0] must be an integer
86+
"""
87+
if not isinstance(number, int):
88+
message = f"Input value of [{number=}] must be an integer"
89+
raise TypeError(message)
90+
91+
if number <= 0:
92+
message = f"Input value of [{number=}] must be > 0"
93+
raise ValueError(message)
94+
95+
if number == 1:
96+
return False
97+
98+
number -= 1
99+
n = 0
100+
while number % 2 == 0:
101+
n += 1
102+
number //= 2
103+
return number < 2**n
104+
105+
62106
if __name__ == "__main__":
63107
import doctest
64108

@@ -73,3 +117,9 @@ def proth(number: int) -> int:
73117
continue
74118

75119
print(f"The {number}th Proth number: {value}")
120+
121+
for number in [1, 2, 3, 4, 5, 9, 13, 49, 57, 193, 241, 163, 201]:
122+
if is_proth_number(number):
123+
print(f"{number} is a Proth number")
124+
else:
125+
print(f"{number} is not a Proth number")

strings/palindrome.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"BB": True,
1212
"ABC": False,
1313
"amanaplanacanalpanama": True, # "a man a plan a canal panama"
14+
"abcdba": False,
15+
"AB": False,
1416
}
1517
# Ensure our test data is valid
1618
assert all((key == key[::-1]) is value for key, value in test_data.items())
@@ -61,7 +63,7 @@ def is_palindrome_recursive(s: str) -> bool:
6163
>>> all(is_palindrome_recursive(key) is value for key, value in test_data.items())
6264
True
6365
"""
64-
if len(s) <= 2:
66+
if len(s) <= 1:
6567
return True
6668
if s[0] == s[len(s) - 1]:
6769
return is_palindrome_recursive(s[1:-1])

0 commit comments

Comments
 (0)