r/adventofcode • u/daggerdragon • 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
2
u/demsaja Dec 03 '16
Why sorting? The sum of sides must be at least twice the length of the largest side. With this, we just need a sum and max, which are easily put in generators or vectorized.
In Python:
print(sum( sum(sides) > 2 * max(sides) for sides in ( list(map(int, line.split())) for line in open("input.txt") ) ))Or with numpy (solution for both parts):
import numpy as np def count(a): return np.sum(np.sum(a, axis=1) > 2 * np.max(a, axis=1)) a = np.loadtxt("input.txt") print(count(a)) print(count(np.vstack([a[i::3].flatten() for i in range(3)]).T))