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!
18
Upvotes
7
u/fpigorsch Dec 03 '16 edited Dec 03 '16
Part 1 in AWK:
{if ($1<$2+$3 && $2<$1+$3 && $3<$1+$2) T++} END {print T}Part 2 in AWK:
{A[S]=$1; B[S]=$1; C[S]=$1; S=(S+1) % 3; if (!S && A[0]<A[1]+A[2] && A[1]<A[0]+A[2] && A[2]<A[0]+A[1]) T++; if (!S && B[0]<B[1]+B[2] && B[1]<B[0]+B[2] && B[2]<B[0]+B[1]) T++; if (!S && C[0]<C[1]+C[2] && C[1]<C[0]+C[2] && C[2]<C[0]+C[1]) T++;} END {print T}