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

Function solution

project_euler/problem_101/sol1.py:191–216  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

189
190
191def 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
219if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 2

funcFunction · 0.85
interpolateFunction · 0.85

Tested by

no test coverage detected