Skip to content

Instantly share code, notes, and snippets.

@kylethebaker
Created December 3, 2016 08:30
Show Gist options
  • Save kylethebaker/dd73057a2539e51162ed3e6c455eaab2 to your computer and use it in GitHub Desktop.
Save kylethebaker/dd73057a2539e51162ed3e6c455eaab2 to your computer and use it in GitHub Desktop.
import sys
def is_triangle(tri):
return all([tri[i%3] + tri[(i+1)%3] > tri[(i+2)%3] for i in range(3)])
in_str = [line.strip() for line in sys.stdin.readlines()]
in_list = [[int(side) for side in line.split()] for line in in_str]
print("part 1: ", len(list(filter(is_triangle, in_list))))
triangles = []
while in_list:
square = [in_list.pop() for _ in range(3)]
for triangle in [[square[y][x] for y in range(3)] for x in range(3)]:
triangles.append(triangle)
print("part 2: ", len(list(filter(is_triangle, triangles))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment