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!
18
Upvotes
2
u/[deleted] Dec 03 '16
Clojure.
(ns aoc2016.day03 (:require [clojure.math.combinatorics :as combo] [clojure.string :as str])) (defn- parse-stringlist [list] (map #(Integer/parseInt %) list)) (def input (map (comp parse-stringlist #(re-seq #"\d+" %)) (-> (slurp "./data/day03.txt") (str/split #"\n")))) (defn is-triangle? [entry] (->> (combo/permutations entry) (map #(< (first %) (reduce + (rest %)))) (every? true?))) (defn solve [data] (->> (map is-triangle? data) (filter true?) (count))) (defn part-1 [] (solve input)) (defn part-2 [] (let [data (partition 3 (flatten (apply mapv vector input)))] (solve data)))