project_euler.problem_102.sol1 ============================== .. py:module:: project_euler.problem_102.sol1 .. autoapi-nested-parse:: Three distinct points are plotted at random on a Cartesian plane, for which -1000 ≤ x, y ≤ 1000, such that a triangle is formed. Consider the following two triangles: A(-340,495), B(-153,-910), C(835,-947) X(-175,41), Y(-421,-714), Z(574,-645) It can be verified that triangle ABC contains the origin, whereas triangle XYZ does not. Using triangles.txt (right click and 'Save Link/Target As...'), a 27K text file containing the coordinates of one thousand "random" triangles, find the number of triangles for which the interior contains the origin. NOTE: The first two examples in the file represent the triangles in the example given above. Functions --------- .. autoapisummary:: project_euler.problem_102.sol1.contains_origin project_euler.problem_102.sol1.solution project_euler.problem_102.sol1.vector_product Module Contents --------------- .. py:function:: contains_origin(x1: int, y1: int, x2: int, y2: int, x3: int, y3: int) -> bool Check if the triangle given by the points A(x1, y1), B(x2, y2), C(x3, y3) contains the origin. >>> contains_origin(-340, 495, -153, -910, 835, -947) True >>> contains_origin(-175, 41, -421, -714, 574, -645) False .. py:function:: solution(filename: str = 'p102_triangles.txt') -> int Find the number of triangles whose interior contains the origin. >>> solution("test_triangles.txt") 1 .. py:function:: vector_product(point1: tuple[int, int], point2: tuple[int, int]) -> int Return the 2-d vector product of two vectors. >>> vector_product((1, 2), (-5, 0)) 10 >>> vector_product((3, 1), (6, 10)) 24