Find the sum of the FITs of the BOPS. For each interpolating polynomial of order 1, 2, ... , 10, find the first x such that the value of the polynomial at x does not equal u(x). >>> solution(lambda n: n ** 3, 3) 74
(func: Callable[[int], int] = question_function, order: int = 10)
| 189 | |
| 190 | |
| 191 | def solution(func: Callable[[int], int] = question_function, order: int = 10) -> int: |
| 192 | """ |
| 193 | Find the sum of the FITs of the BOPS. For each interpolating polynomial of order |
| 194 | 1, 2, ... , 10, find the first x such that the value of the polynomial at x does |
| 195 | not equal u(x). |
| 196 | >>> solution(lambda n: n ** 3, 3) |
| 197 | 74 |
| 198 | """ |
| 199 | data_points: list[int] = [func(x_val) for x_val in range(1, order + 1)] |
| 200 | |
| 201 | polynomials: list[Callable[[int], int]] = [ |
| 202 | interpolate(data_points[:max_coeff]) for max_coeff in range(1, order + 1) |
| 203 | ] |
| 204 | |
| 205 | ret: int = 0 |
| 206 | poly: Callable[[int], int] |
| 207 | x_val: int |
| 208 | |
| 209 | for poly in polynomials: |
| 210 | x_val = 1 |
| 211 | while func(x_val) == poly(x_val): |
| 212 | x_val += 1 |
| 213 | |
| 214 | ret += poly(x_val) |
| 215 | |
| 216 | return ret |
| 217 | |
| 218 | |
| 219 | if __name__ == "__main__": |
no test coverage detected