r/adventofcode • • Dec 03 '16

SOLUTION MEGATHREAD --- 2016 Day 3 Solutions ---

--- Day 3: Squares With Three Sides ---

Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).


DECKING THE HALLS WITH BOUGHS OF HOLLY IS MANDATORY [?]

This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

17 Upvotes

234 comments sorted by

View all comments

Show parent comment

1

u/miran1 Dec 03 '16

both parts, based on your idea:

import numpy as np

in_ = np.loadtxt('./03 - Squares With Three Sides.txt')

def find_triangles(arr):
    arr.sort(axis=1)
    return sum(np.sum(arr[:, :2], axis=1) > arr[:, 2])

print(find_triangles(in_.copy()))
print(find_triangles(in_.T.reshape(-1, 3)))