From 484e507af114c5db8aac22dd66e9c35aea9d4fd4 Mon Sep 17 00:00:00 2001 From: Adam Jeniski Date: Thu, 23 Apr 2026 15:36:25 -0400 Subject: [PATCH] init 2017 --- 2017/.gitignore | 4 ++++ 2017/project.clj | 15 +++++++++++++++ 2017/src/day01.clj | 26 ++++++++++++++++++++++++++ 2017/src/day02.clj | 25 +++++++++++++++++++++++++ 2017/src/day04.clj | 20 ++++++++++++++++++++ 2017/src/user.clj | 11 +++++++++++ 6 files changed, 101 insertions(+) create mode 100644 2017/.gitignore create mode 100644 2017/project.clj create mode 100644 2017/src/day01.clj create mode 100644 2017/src/day02.clj create mode 100644 2017/src/day04.clj create mode 100644 2017/src/user.clj diff --git a/2017/.gitignore b/2017/.gitignore new file mode 100644 index 0000000..57a76f9 --- /dev/null +++ b/2017/.gitignore @@ -0,0 +1,4 @@ +input/ +.lein-repl-history +.idea/ +*.iml \ No newline at end of file diff --git a/2017/project.clj b/2017/project.clj new file mode 100644 index 0000000..a003cad --- /dev/null +++ b/2017/project.clj @@ -0,0 +1,15 @@ +(defproject org.ajet/advent-of-code "0.0.0-SNAPSHOT" + :description "my 2017 advent of code solutions in clojure" + :url "http://github.com/ajetski/advent-of-code" + :min-lein-version "2.0.0" + :jvm-opts ["-Xmx16g"] + :plugins [[cider/cider-nrepl "0.57.0"]] + :dependencies [[org.clojure/clojure "1.12.0"] + [org.clojure/data.priority-map "1.2.0"] + [org.clojure/math.combinatorics "0.3.0"] + [babashka/fs "0.5.23"] + [org.babashka/http-client "0.4.22"] + [org.clojure/core.match "1.1.0"] + [clj-python/libpython-clj "2.025"] + [tools.aqua/z3-turnkey "4.14.1"]] + :source-paths ["src" "../shared/clj/src"]) diff --git a/2017/src/day01.clj b/2017/src/day01.clj new file mode 100644 index 0000000..1e2b05f --- /dev/null +++ b/2017/src/day01.clj @@ -0,0 +1,26 @@ +(ns day01 + (:require input-manager)) + +(defn to-digit [c] (Character/digit c 10)) + +(def input (mapv to-digit (input-manager/get-input-raw 2017 01))) + +(defn solve [offset] + (let [lookup (fn [idx] + (input (mod idx (count input))))] + (->> input + (map-indexed vector) + (filter (fn [[idx el]] + (= el (lookup (+ offset idx))))) + (map second) + (apply +)))) + +;; part 1 +(solve 1) + + + +;; part 2 +(solve (/ (count input) 2)) + + diff --git a/2017/src/day02.clj b/2017/src/day02.clj new file mode 100644 index 0000000..97d24c4 --- /dev/null +++ b/2017/src/day02.clj @@ -0,0 +1,25 @@ +(ns day02 + (:require input-manager + core)) + +(def input (mapv (comp #(mapv parse-long %) + core/split-whitespace) + (input-manager/get-input 2017 02))) + +;; part 1 +(->> input + (map (comp #(apply - %) + (juxt #(apply max %) + #(apply min %)))) + (apply +)) + +(defn find-divisible [l] + (or (first + (for [a (range (count l)) + b (range (count l)) + :when (and (not= a b) + (= (mod (l a) (l b)) 0))] + (/ (l a) (l b)))) + 0)) + +(apply + (map find-divisible input)) diff --git a/2017/src/day04.clj b/2017/src/day04.clj new file mode 100644 index 0000000..da71569 --- /dev/null +++ b/2017/src/day04.clj @@ -0,0 +1,20 @@ +(ns day04 + (:require input-manager + core)) + +(def input (map core/split-whitespace (input-manager/get-input 2017 04))) + +;; part 1 +(->> input + (filter #(= (count %) + (count (into #{} %)))) + count) + +;; part 2 +(->> input + (filter (fn [l] + (= (count (into #{} (map frequencies l))) + (count l)))) + + count) + diff --git a/2017/src/user.clj b/2017/src/user.clj new file mode 100644 index 0000000..f964bef --- /dev/null +++ b/2017/src/user.clj @@ -0,0 +1,11 @@ +(ns user + (:require + [clojure.pprint :as pprint])) + +(defonce printer (bound-fn* pprint/pprint)) +(add-tap printer) + +(comment + ;; tap debugging + (remove-tap printer)) +