2016-12-03 - Squares With Three Sides
(original .ipynb)puzzle_input_str = open("puzzle_input/day3.txt").read() def is_valid(tri): a, b, c = sorted(tri) return a + b > c def part_one(input_str): count = 0 for line in input_str.split("\n"): tri = [int(s) for s in line.strip().split(" ") if s != ""] if is_valid(tri): count += 1 return count print("part one:", part_one(puzzle_input_str))
part one: 862
def part_two(input_str): count = 0 tri_a, tri_b, tri_c = [], [], [] maybe_triangles = [] for line in input_str.split("\n"): a, b, c = [int(s) for s in line.strip().split(" ") if s != "" ] tri_a.append(a) tri_b.append(b) tri_c.append(c) if len(tri_a) == 3: maybe_triangles += [tri_a, tri_b, tri_c] tri_a, tri_b, tri_c = [], [], [] return sum(1 for t in maybe_triangles if is_valid(t)) print("part two:", part_two(puzzle_input_str))
part two: 1577