Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check(points):
- tempstr, locations, positive, negative, valid = "", [], False, False, False
- for x in str(points):
- if x == ",":
- locations.append(int(tempstr))
- tempstr = ""
- continue
- tempstr += x
- locations.append(int(tempstr))
- lefttoright = sorted(([locations[0], locations[1]], [locations[2], locations[3]], [locations[4], locations[5]]))
- print(lefttoright)
- for x in range(3):
- if lefttoright[x][0] > 0:
- positive = True
- if lefttoright[x][0] < 0:
- negative = True
- if positive and negative:
- valid = True
- if not valid:
- return False
- positive, negative = False, False
- for x in range(3):
- if lefttoright[x][1] > 0:
- positive = True
- if lefttoright[x][1] < 0:
- negative = True
- if positive and negative:
- valid = True
- if not valid:
- return False
- slope = (lefttoright[0][1] - lefttoright[2][1]) / (lefttoright[0][0] - lefttoright[2][0])
- yintercept1 = lefttoright[0][1] + slope*abs(lefttoright[0][0])
- print(slope, yintercept1)
- if 0 < lefttoright[1][0]:
- slope2 = (lefttoright[0][1] - lefttoright[1][1]) / (lefttoright[0][0] - lefttoright[1][0])
- yintercept2 = lefttoright[0][1] + slope2*abs(lefttoright[0][0])
- print(slope2, yintercept2)
- elif 0 > lefttoright[1][0]:
- slope2 = (lefttoright[1][1] - lefttoright[2][1]) / (lefttoright[1][0] - lefttoright[2][0])
- yintercept2 = lefttoright[1][1] + slope2*abs(lefttoright[1][0])
- print(slope2, yintercept2)
- if yintercept2 < 0 < yintercept1 or yintercept1 < 0 < yintercept2:
- return True
- return False
- answer = 0
- for a in open("triangles.txt"):
- if check(a.rstrip()):
- answer += 1
- print(answer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement