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

Function fraction_list

project_euler/problem_033/sol1.py:29–57  ·  view source on GitHub ↗

>>> fraction_list(2) ['16/64', '19/95', '26/65', '49/98'] >>> fraction_list(3) ['16/64', '19/95', '26/65', '49/98'] >>> fraction_list(4) ['16/64', '19/95', '26/65', '49/98'] >>> fraction_list(0) [] >>> fraction_list(5) ['16/64', '19/95', '26/65', '49/98']

(digit_len: int)

Source from the content-addressed store, hash-verified

27
28
29def fraction_list(digit_len: int) -> list[str]:
30 """
31 >>> fraction_list(2)
32 ['16/64', '19/95', '26/65', '49/98']
33 >>> fraction_list(3)
34 ['16/64', '19/95', '26/65', '49/98']
35 >>> fraction_list(4)
36 ['16/64', '19/95', '26/65', '49/98']
37 >>> fraction_list(0)
38 []
39 >>> fraction_list(5)
40 ['16/64', '19/95', '26/65', '49/98']
41 """
42 solutions = []
43 den = 11
44 last_digit = int("1" + "0" * digit_len)
45 for num in range(den, last_digit):
46 while den <= 99:
47 if (
48 (num != den)
49 and (num % 10 == den // 10)
50 and (den % 10 != 0)
51 and is_digit_cancelling(num, den)
52 ):
53 solutions.append(f"{num}/{den}")
54 den += 1
55 num += 1
56 den = 10
57 return solutions
58
59
60def solution(n: int = 2) -> int:

Callers 1

solutionFunction · 0.85

Calls 2

is_digit_cancellingFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected