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
from math import sqrt | |
import time | |
SQRT_2 = sqrt(2) | |
INFINITY = float('inf') | |
def get_val(row, i): | |
return row[i] if i >=0 and i < len(row) else '.' | |
def next_row(row): |
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) |
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
print len([tri for tri in map(sorted, zip(*(iter([item for sublist in map(list, zip(*[map(int, line.strip().split()) for line in open("input_1.txt").readlines()])) for item in sublist]),) * 3)) if tri[0] + tri[1] > tri[2]]) |