MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_026/sol1.py:27–53  ·  view source on GitHub ↗

Considering any range can be provided, because as per the problem, the digit d < 1000 >>> solution(1, 10) 7 >>> solution(10, 100) 97 >>> solution(10, 1000) 983

(numerator: int = 1, digit: int = 1000)

Source from the content-addressed store, hash-verified

25
26
27def solution(numerator: int = 1, digit: int = 1000) -> int:
28 """
29 Considering any range can be provided,
30 because as per the problem, the digit d < 1000
31 >>> solution(1, 10)
32 7
33 >>> solution(10, 100)
34 97
35 >>> solution(10, 1000)
36 983
37 """
38 the_digit = 1
39 longest_list_length = 0
40
41 for divide_by_number in range(numerator, digit + 1):
42 has_been_divided: list[int] = []
43 now_divide = numerator
44 for _ in range(1, digit + 1):
45 if now_divide in has_been_divided:
46 if longest_list_length < len(has_been_divided):
47 longest_list_length = len(has_been_divided)
48 the_digit = divide_by_number
49 else:
50 has_been_divided.append(now_divide)
51 now_divide = now_divide * 10 % divide_by_number
52
53 return the_digit
54
55
56# Tests

Callers

nothing calls this directly

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected