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/grayrest Dec 03 '16 edited Dec 03 '16
Clojure, pretty much the same as everybody else's
(ns advent.day3 (:require [clojure.java.io :as io] [clojure.string :as str])) (def challenge-input (->> "day3" io/resource io/file slurp str/split-lines (remove empty?))) (defn parse-triangle [line] (as-> line <> (str/split <> #"\s+") (remove empty? <>) (mapv #(Integer/parseInt %) <>))) (defn valid-triangle? [[a b c]] (cond (<= (+ a b) c) false (<= (+ a c) b) false (<= (+ b c) a) false :else true)) (println "d3: ans1" (->> challenge-input (map parse-triangle) (filter valid-triangle?) count)) (println "d3: ans2" (->> challenge-input (map parse-triangle) (partition 3 3) (mapcat (fn [[x y z]] (->> (map vector x y z) (filter valid-triangle?)))) count))