Skip to content

Commit cbbc43b

Browse files
realDuYuanChaogithub-actionscclauss
authored
Updated problem_04 in project_euler (#2427)
* Updated problem_04 in project_euler * fixup! Format Python code with psf/black push * That number is larger than our acceptable range. * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
1 parent 10aa214 commit cbbc43b

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Diff for: DIRECTORY.md

+6
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@
8585
* [Harriscorner](https://github.com/TheAlgorithms/Python/blob/master/computer_vision/harriscorner.py)
8686

8787
## Conversions
88+
* [Binary To Decimal](https://github.com/TheAlgorithms/Python/blob/master/conversions/binary_to_decimal.py)
8889
* [Decimal To Any](https://github.com/TheAlgorithms/Python/blob/master/conversions/decimal_to_any.py)
8990
* [Decimal To Binary](https://github.com/TheAlgorithms/Python/blob/master/conversions/decimal_to_binary.py)
9091
* [Decimal To Hexadecimal](https://github.com/TheAlgorithms/Python/blob/master/conversions/decimal_to_hexadecimal.py)
9192
* [Decimal To Octal](https://github.com/TheAlgorithms/Python/blob/master/conversions/decimal_to_octal.py)
93+
* [Hexadecimal To Decimal](https://github.com/TheAlgorithms/Python/blob/master/conversions/hexadecimal_to_decimal.py)
9294
* [Prefix Conversions](https://github.com/TheAlgorithms/Python/blob/master/conversions/prefix_conversions.py)
9395
* [Roman To Integer](https://github.com/TheAlgorithms/Python/blob/master/conversions/roman_to_integer.py)
9496
* [Temperature Conversions](https://github.com/TheAlgorithms/Python/blob/master/conversions/temperature_conversions.py)
@@ -222,6 +224,8 @@
222224
## File Transfer
223225
* [Receive File](https://github.com/TheAlgorithms/Python/blob/master/file_transfer/receive_file.py)
224226
* [Send File](https://github.com/TheAlgorithms/Python/blob/master/file_transfer/send_file.py)
227+
* Tests
228+
* [Test Send File](https://github.com/TheAlgorithms/Python/blob/master/file_transfer/tests/test_send_file.py)
225229

226230
## Fuzzy Logic
227231
* [Fuzzy Operations](https://github.com/TheAlgorithms/Python/blob/master/fuzzy_logic/fuzzy_operations.py)
@@ -725,6 +729,7 @@
725729
* [Binary Tree Traversals](https://github.com/TheAlgorithms/Python/blob/master/traversals/binary_tree_traversals.py)
726730

727731
## Web Programming
732+
* [Covid Stats Via Xpath](https://github.com/TheAlgorithms/Python/blob/master/web_programming/covid_stats_via_xpath.py)
728733
* [Crawl Google Results](https://github.com/TheAlgorithms/Python/blob/master/web_programming/crawl_google_results.py)
729734
* [Current Stock Price](https://github.com/TheAlgorithms/Python/blob/master/web_programming/current_stock_price.py)
730735
* [Current Weather](https://github.com/TheAlgorithms/Python/blob/master/web_programming/current_weather.py)
@@ -735,5 +740,6 @@
735740
* [Fetch Jobs](https://github.com/TheAlgorithms/Python/blob/master/web_programming/fetch_jobs.py)
736741
* [Get Imdb Top 250 Movies Csv](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_imdb_top_250_movies_csv.py)
737742
* [Get Imdbtop](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_imdbtop.py)
743+
* [Recaptcha Verification](https://github.com/TheAlgorithms/Python/blob/master/web_programming/recaptcha_verification.py)
738744
* [Slack Message](https://github.com/TheAlgorithms/Python/blob/master/web_programming/slack_message.py)
739745
* [World Covid19 Stats](https://github.com/TheAlgorithms/Python/blob/master/web_programming/world_covid19_stats.py)

Diff for: project_euler/problem_04/sol1.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,34 @@ def solution(n):
1818
29992
1919
>>> solution(40000)
2020
39893
21+
>>> solution(10000)
22+
Traceback (most recent call last):
23+
...
24+
ValueError: That number is larger than our acceptable range.
2125
"""
2226
# fetches the next number
23-
for number in range(n - 1, 10000, -1):
27+
for number in range(n - 1, 9999, -1):
2428

2529
# converts number into string.
26-
strNumber = str(number)
30+
str_number = str(number)
2731

28-
# checks whether 'strNumber' is a palindrome.
29-
if strNumber == strNumber[::-1]:
32+
# checks whether 'str_number' is a palindrome.
33+
if str_number == str_number[::-1]:
3034

3135
divisor = 999
3236

3337
# if 'number' is a product of two 3-digit numbers
3438
# then number is the answer otherwise fetch next number.
3539
while divisor != 99:
36-
if (number % divisor == 0) and (len(str(int(number / divisor))) == 3):
40+
if (number % divisor == 0) and (len(str(number // divisor)) == 3.0):
3741
return number
3842
divisor -= 1
43+
raise ValueError("That number is larger than our acceptable range.")
3944

4045

4146
if __name__ == "__main__":
47+
import doctest
48+
49+
doctest.testmod()
50+
4251
print(solution(int(input().strip())))

0 commit comments

Comments
 (0)