Skip to content

Instantly share code, notes, and snippets.

@pedrosorio
Created December 4, 2016 18:32
Show Gist options
  • Save pedrosorio/18488f23439cd0fcf2037b4477deb55d to your computer and use it in GitHub Desktop.
Save pedrosorio/18488f23439cd0fcf2037b4477deb55d to your computer and use it in GitHub Desktop.
rows = [map(int, line.strip().split()) for line in open("input_1.txt").readlines()]
columns = map(list, zip(*rows))
flattened = [item for sublist in columns for item in sublist]
groups_of_3 = zip(*(iter(flattened),) * 3)
with_sorted_lengths = map(sorted, groups_of_3)
only_valid_triangles = [tri for tri in with_sorted_lengths if tri[0] + tri[1] > tri[2]]
print len(only_valid_triangles)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment