init 2017

This commit is contained in:
Adam Jeniski
2026-04-23 15:36:25 -04:00
parent 7057247936
commit 484e507af1
6 changed files with 101 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
input/
.lein-repl-history
.idea/
*.iml
+15
View File
@@ -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"])
+26
View File
@@ -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))
+25
View File
@@ -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))
+20
View File
@@ -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)
+11
View File
@@ -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))