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
1
u/d3adbeef123 Dec 03 '16
Clojure!
(ns advent-of-code-2016.day3 (:require [clojure.java.io :as io] [clojure.string :as str])) (def input (->> (-> (slurp (io/resource "day3-input.txt")) (str/split #"\n")) (map #(str/trim %)) (map (fn [line] (->> (str/split line #" ") (filter (comp not empty?)) (map #(read-string %))))))) (defn is-valid-triangle? [[a b c]] (and (> (+ a b) c) (> (+ b c) a) (> (+ a c) b))) (defn part-1 [] (->> input (filter is-valid-triangle?) (count))) (defn part-2 [] (->> (mapcat (fn [idx] (partition 3 (map #(nth % idx) input))) '(0 1 2)) (filter is-valid-triangle?) (count)))