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

Function solution

project_euler/problem_102/sol1.py:60–78  ·  view source on GitHub ↗

Find the number of triangles whose interior contains the origin. >>> solution("test_triangles.txt") 1

(filename: str = "p102_triangles.txt")

Source from the content-addressed store, hash-verified

58
59
60def 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
81if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 3

contains_originFunction · 0.85
splitMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected