Problem 102 - Triangle Containment
I really enjoyed solving this problem, using a clever application of the vector product and checking if the 3 outputs had the same sign.
import re
import math
import matplotlib.pyplot as plt
pattern = re.compile(r'-?\d+')
NoTriangles = 0
with open('triangles.txt', 'r') as file:
for line in file:
numbers = pattern.findall(line)
a, b, c, d, e, f = map(int, numbers)
Cross1 = a*(d-b) - b*(c -a)
Cross2 = c*(f-d) - d*(e-c)
Cross3 = e*(b-f) - f*(a - e)
if (Cross1 > 0 and Cross2 > 0 and Cross3 > 0) or (Cross1 < 0 and Cross2 < 0 and Cross3 < 0):
NoTriangles += 1
print(NoTriangles)
Gives an output of 228