Day 3 - Advent of Code 2016

Working solutions for the day 3 puzzles.

Part One

""" day_03_01.py """

# usage: python3 day_03_01.py < input


def possible(s1, s2, s3):
    """ can these side lengths form a triangle """
    return all([s1 + s2 > s3,
                s1 + s3 > s2,
                s2 + s3 > s1])


count = 0
while True:
    try:
        triangle = input()
    except EOFError:
        break
    x, y, z = [int(i) for i in triangle.split()]
    if possible(x, y, z):
        count += 1

print(count)

Part Two

""" day_03_02.py """

# usage: python3 day_03_02.py < input


def possible(s1, s2, s3):
    """ can these side lengths form a triangle """
    return all([s1 + s2 > s3,
                s1 + s3 > s2,
                s2 + s3 > s1])


count = 0
while True:
    try:
        triangles = []
        for _ in range(3):
            line = input()
            triangles.append([int(i) for i in line.split()])
    except EOFError:
        break

    for i in range(3):
        x, y, z = triangles[0][i], triangles[1][i], triangles[2][i]
        if possible(x, y, z):
            count += 1

print(count)