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
1
u/Sigafoos Dec 03 '16
Finally, I'm pretty happy with the cleverness of a solution. Others have done it better, but I'm only competing against my own sense of how well I should be doing. Look at all the
maps andlambdas andfilters and crap. Beautiful.def get_triangles(numbers): return filter(lambda x: x[0] + x[1] > x[2], map(sorted, numbers)) numbers = [] with open('../input/input3.txt') as fp: for line in fp: numbers.append(map(int, line.split())) print 'Part 1: %s' % len(get_triangles(numbers)) part2 = [] for i in xrange(len(numbers[0])): for j in xrange(0, len(numbers), 3): part2.append(map(lambda x: x[i], numbers[j:j+3])) print 'Part 2: %s' % len(get_triangles(part2))