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

Function solution

project_euler/problem_144/sol1.py:78–96  ·  view source on GitHub ↗

Return the number of times that the beam hits the interior wall of the cell before exiting. >>> solution(0.00001,-10) 1 >>> solution(5, 0) 287

(first_x_coord: float = 1.4, first_y_coord: float = -9.6)

Source from the content-addressed store, hash-verified

76
77
78def solution(first_x_coord: float = 1.4, first_y_coord: float = -9.6) -> int:
79 """
80 Return the number of times that the beam hits the interior wall of the
81 cell before exiting.
82 >>> solution(0.00001,-10)
83 1
84 >>> solution(5, 0)
85 287
86 """
87 num_reflections: int = 0
88 point_x: float = first_x_coord
89 point_y: float = first_y_coord
90 gradient: float = (10.1 - point_y) / (0.0 - point_x)
91
92 while not (-0.01 <= point_x <= 0.01 and point_y > 0):
93 point_x, point_y, gradient = next_point(point_x, point_y, gradient)
94 num_reflections += 1
95
96 return num_reflections
97
98
99if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

next_pointFunction · 0.85

Tested by

no test coverage detected