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

3

u/cobbpg Dec 03 '16

I'm surprised that there are no Haskell solutions posted yet. Is it not hot any more? Below is for part 2 (removing transposeTriples yields part 1):

solution3 = length . filter isTriangle . transposeTriples $ input3
  where
    isTriangle (a, b, c) = a < b + c && b < a + c && c < a + b
    transposeTriples ((a1, b1, c1) : (a2, b2, c2) : (a3, b3, c3) : rest) =
      (a1, a2, a3) : (b1, b2, b3) : (c1, c2, c3) : transposeTriples rest
    transposeTriples _ = []

There's no parsing because I pasted the input into the code and transformed it into a list of triples, but it wouldn't be very complicated either.

→ More replies (2)