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
)
| 67 | |
| 68 | |
| 69 | def 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 | |
| 88 | def solution(order: int = 35) -> int: |