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

Function interpolated_func

project_euler/problem_101/sol1.py:145–159  ·  view source on GitHub ↗

>>> interpolate([1])(3) 1 >>> interpolate([1, 8])(3) 15 >>> interpolate([1, 8, 27])(4) 58 >>> interpolate([1, 8, 27, 64])(6) 216

(var: int)

Source from the content-addressed store, hash-verified

143 coeffs = solve(matrix, vector)
144
145 def interpolated_func(var: int) -> int:
146 """
147 >>> interpolate([1])(3)
148 1
149 >>> interpolate([1, 8])(3)
150 15
151 >>> interpolate([1, 8, 27])(4)
152 58
153 >>> interpolate([1, 8, 27, 64])(6)
154 216
155 """
156 return sum(
157 round(coeffs[x_val][0]) * (var ** (size - x_val - 1))
158 for x_val in range(size)
159 )
160
161 return interpolated_func
162

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected