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

Function add_three

project_euler/problem_180/sol1.py:69–85  ·  view source on GitHub ↗

Given the numerators and denominators of three fractions, return the numerator and denominator of their sum in lowest form. >>> add_three(1, 3, 1, 3, 1, 3) (1, 1) >>> add_three(2, 5, 4, 11, 12, 3) (262, 55)

(
    x_num: int, x_den: int, y_num: int, y_den: int, z_num: int, z_den: int
)

Source from the content-addressed store, hash-verified

67
68
69def add_three(
70 x_num: int, x_den: int, y_num: int, y_den: int, z_num: int, z_den: int
71) -> tuple[int, int]:
72 """
73 Given the numerators and denominators of three fractions, return the
74 numerator and denominator of their sum in lowest form.
75 >>> add_three(1, 3, 1, 3, 1, 3)
76 (1, 1)
77 >>> add_three(2, 5, 4, 11, 12, 3)
78 (262, 55)
79 """
80 top: int = x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
81 bottom: int = x_den * y_den * z_den
82 hcf: int = gcd(top, bottom)
83 top //= hcf
84 bottom //= hcf
85 return top, bottom
86
87
88def solution(order: int = 35) -> int:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected