Skip to content

Commit 9b2d65b

Browse files
shuklalokcclauss
andauthored
Solution for Euler Problem 26 (TheAlgorithms#1939)
* Solution for Euler Problem 26 * Update project_euler/problem_26/sol1.py typo error fix. Co-authored-by: Christian Clauss <[email protected]> * Update project_euler/problem_26/sol1.py typo error fix Co-authored-by: Christian Clauss <[email protected]> * Update project_euler/problem_26/sol1.py ok to remove, this comes from Pycharm automatically when docstring is added. Co-authored-by: Christian Clauss <[email protected]> * Update project_euler/problem_26/sol1.py ok to remove. Co-authored-by: Christian Clauss <[email protected]> * Update project_euler/problem_26/sol1.py Co-authored-by: Christian Clauss <[email protected]> * Update project_euler/problem_26/sol1.py Co-authored-by: Christian Clauss <[email protected]> * Update project_euler/problem_26/sol1.py Co-authored-by: Christian Clauss <[email protected]> * now_divide = now_divide * 10 % divide_by_number Co-authored-by: Christian Clauss <[email protected]>
1 parent f80ffe1 commit 9b2d65b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

project_euler/problem_26/__init__.py

Whitespace-only changes.

project_euler/problem_26/sol1.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Euler Problem 26
3+
https://projecteuler.net/problem=26
4+
Find the value of d < 1000 for which 1/d contains the longest recurring cycle
5+
in its decimal fraction part.
6+
"""
7+
8+
def find_digit(numerator: int, digit: int) -> int:
9+
"""
10+
Considering any range can be provided,
11+
because as per the problem, the digit d < 1000
12+
>>> find_digit(1, 10)
13+
7
14+
>>> find_digit(10, 100)
15+
97
16+
>>> find_digit(10, 1000)
17+
983
18+
"""
19+
the_digit = 1
20+
longest_list_length = 0
21+
22+
for divide_by_number in range(numerator, digit + 1):
23+
has_been_divided = []
24+
now_divide = numerator
25+
for division_cycle in range(1, digit + 1):
26+
if now_divide in has_been_divided:
27+
if longest_list_length < len(has_been_divided):
28+
longest_list_length = len(has_been_divided)
29+
the_digit = divide_by_number
30+
else:
31+
has_been_divided.append(now_divide)
32+
now_divide = now_divide * 10 % divide_by_number
33+
34+
return the_digit
35+
36+
37+
# Tests
38+
if __name__ == "__main__":
39+
import doctest
40+
41+
doctest.testmod()

0 commit comments

Comments
 (0)