Find the number of triangles whose interior contains the origin. >>> solution("test_triangles.txt") 1
(filename: str = "p102_triangles.txt")
| 58 | |
| 59 | |
| 60 | def solution(filename: str = "p102_triangles.txt") -> int: |
| 61 | """ |
| 62 | Find the number of triangles whose interior contains the origin. |
| 63 | >>> solution("test_triangles.txt") |
| 64 | 1 |
| 65 | """ |
| 66 | data: str = Path(__file__).parent.joinpath(filename).read_text(encoding="utf-8") |
| 67 | |
| 68 | triangles: list[list[int]] = [] |
| 69 | for line in data.strip().split("\n"): |
| 70 | triangles.append([int(number) for number in line.split(",")]) |
| 71 | |
| 72 | ret: int = 0 |
| 73 | triangle: list[int] |
| 74 | |
| 75 | for triangle in triangles: |
| 76 | ret += contains_origin(*triangle) |
| 77 | |
| 78 | return ret |
| 79 | |
| 80 | |
| 81 | if __name__ == "__main__": |
no test coverage detected