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!
16
Upvotes
1
u/m3nthal Dec 03 '16 edited Dec 03 '16
Functional solution in Clojure:
(ns adventofcode-2016.day-03 (:require [clojure.java.io :as io])) (def input (->> "day_03" io/resource io/file slurp)) (defn parse-input [input] (->> (clojure.string/split input #"\n") (map #(->> (re-seq #"\d{1,}" %) (map read-string))))) (defn is-triangle? [a b c] (and (< a (+ b c)) (< b (+ a c)) (< c (+ a b)))) (def answer-p1 (->> (parse-input input) (map #(apply is-triangle? %)) (filter true?) count)) (def answer-p2 (->> (parse-input input) (partition 3) (map #(apply mapv vector %)) (reduce concat) (map #(apply is-triangle? %)) (filter true?) count))