def get_file(fn): for l in open(fn, 'r'): lst = list(map(lambda x: int(x), l.strip().split(','))) yield ((lst[0], lst[1]), (lst[2], lst[3]), (lst[4], lst[5]), (lst[0], lst[1]), (lst[2], lst[3])) def pro_multi(p, q): return p[0] * q[1] - p[1] * q[0] def judge(l): for i in range((len(l) + 1) // 2): if pro_multi(l[i + 1], l[i]) * pro_multi(l[i + 2], l[i]) > 0: return False return True print(len(list(filter(judge, get_file('../resource/triangles.txt')))))