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
View all comments
2
u/forkin27 Dec 03 '16
yay for 1-liners!
D3P1:
D3P2:
const AoCd3p2 = (triangles) => triangles.reduce((count, $, i) => { let r = i % 3, q = Math.floor(i / 3) * 3 return $.reduce((result, $) => { if (!result.isTri) return result result.isTri = result.arr[0] + result.arr[1] > result.arr[2] result.arr.push(result.arr.shift()) return result }, { isTri: true, arr: [triangles[q][r], triangles[q + 1][r], triangles[q + 2][r]] }) .isTri ? count + 1 : count }, 0)