Skip to content

Instantly share code, notes, and snippets.

View pedrosorio's full-sized avatar

Pedro Osório pedrosorio

View GitHub Profile
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):
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)
@pedrosorio
pedrosorio / day3_part2_one_liner.py
Last active December 4, 2016 23:00
Advent of code day 3 part 2
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]])