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)
| 76 | |
| 77 | |
| 78 | def 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 | |
| 99 | if __name__ == "__main__": |