Created
December 4, 2016 18:32
-
-
Save pedrosorio/18488f23439cd0fcf2037b4477deb55d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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