--- /dev/null
+/target
+/classes
+/checkouts
+profiles.clj
+pom.xml
+pom.xml.asc
+*.jar
+*.class
+/.lein-*
+/.nrepl-port
+.hgignore
+.hg/
+++ /dev/null
-95065
-129298
-145573
-95743
-59139
-78323
-124445
-69015
-81990
-83254
-139274
-92101
-74245
-104038
-61955
-80642
-110376
-89992
-84392
-117830
-140144
-80076
-111285
-107135
-98741
-103753
-141922
-130503
-60409
-73891
-84781
-118319
-93610
-143228
-99616
-65353
-102388
-123813
-88335
-95459
-133635
-108771
-101999
-73850
-106490
-53396
-110330
-140258
-73958
-60273
-101401
-128995
-61495
-114674
-71955
-107049
-79374
-52359
-107925
-91789
-69174
-133966
-85063
-62856
-96965
-97100
-81638
-104488
-131368
-59015
-149357
-65193
-61489
-126089
-141224
-100596
-93144
-109421
-121988
-135890
-70141
-53531
-59900
-98981
-66796
-113700
-109535
-100721
-87240
-99883
-81637
-80064
-143154
-75778
-64835
-59235
-103907
-121637
-118525
-125730
+++ /dev/null
-(ns aoc.core
- [:require [clojure.string :as str]])
-
-(def get-list-from-file
- #(str/split #"," (slurp %)))
-
-(def parse-int
- #(Integer/parseInt %))
-
-(def opcodes {1 +, 2 *})
-(defn perform-operation [[opcode fst snd thd] program]
- (let [opcode-fn (opcodes opcode)
- fst-val (program fst)
- snd-val (program snd)]
- (assoc program thd (opcode-fn fst-val snd-val))))
-
-(defn intcode [program]
- (loop [program program
- counter 0]
- (let [opcode (program counter)]
- (if (= opcode 99)
- program
- (recur (perform-operation (map program (take 4 (iterate inc counter)))
- program)
- (+ counter 4))))))
-
-(defn -main []
- (let [input (mapv parse-int (get-list-from-file "input"))
- fixed-input (assoc input 1 12 2 1)]
- (println (first (intcode fixed-input)))))
-
-(-main)
--- /dev/null
+(defproject adventofcode2019 "0.1.0-SNAPSHOT"
+ :description "Advent of Code 2019"
+ :url "http://example.com/FIXME"
+;;:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
+;; :url "https://www.eclipse.org/legal/epl-2.0/"}
+ :dependencies [[org.clojure/clojure "1.10.0"]
+ [org.clojure/math.combinatorics "0.1.6"]]
+ :main ^:skip-aot adventofcode2019.core
+ :target-path "target/%s"
+ :profiles {:uberjar {:aot :all}})
--- /dev/null
+(ns adventofcode2019.core
+ [:require (adventofcode2019 day01 day02)])
+
+(defn -main
+ ([]
+ (comment run all))
+ ([day]
+ (let [day-str (str "day" (format "%02d" (Integer/parseInt day)))]
+ (eval (read-string (format "(adventofcode2019.%s/%s)" day-str day-str))))))
-(ns aoc.core
- [:require [clojure.string :as str]])
-
-(def get-list-from-file
- #(str/split-lines (slurp %)))
-
-(def parse-int
- #(Integer/parseInt %))
+(ns adventofcode2019.day01
+ [:require [adventofcode2019.lib :refer :all]
+ [clojure.string :as str]])
(defn get-fuel-req [mass]
(reduce + (take-while #(> % 0) (drop 1 (iterate #(- (quot % 3) 2) mass)))))
(defn total-fuel-requirement [input]
(reduce + (map get-fuel-req input)))
-(defn -main []
- (let [input (map parse-int (get-list-from-file "input"))]
+(defn day01 []
+ (let [input (map parse-int (get-list-from-file (input-file)))]
(println (total-fuel-requirement-naive input))
(println (total-fuel-requirement input))))
-
-(-main)
--- /dev/null
+(ns adventofcode2019.day02
+ [:require [adventofcode2019.lib :refer :all]
+ [clojure.string :as str]
+ [clojure.math.combinatorics :as combo]])
+
+(def opcodes {1 +, 2 *})
+(defn perform-operation [[opcode fst snd thd] program]
+ (let [opcode-fn (opcodes opcode)
+ fst-val (program fst)
+ snd-val (program snd)]
+ (assoc program thd (opcode-fn fst-val snd-val))))
+
+(defn intcode [program]
+ (loop [program program
+ counter 0]
+ (let [opcode (program counter)]
+ (if (= opcode 99)
+ program
+ (recur (perform-operation (map program (take 4 (iterate inc counter)))
+ program)
+ (+ counter 4))))))
+
+(defn check-inputs [input noun verb]
+ (let [fixed-input (assoc input 1 noun 2 verb)]
+ (first (intcode fixed-input))))
+
+(defn day02 []
+ (let [input (mapv parse-int (get-list-from-file (input-file) #","))
+ [noun verb] (first (filter (fn [[noun verb]] (= (check-inputs input noun verb) 19690720))
+ (combo/cartesian-product (range 100) (range 100))))]
+ (println (check-inputs input 12 2)) ;; part 1
+ (println (+ (* 100 noun) verb)))) ;; part 2
--- /dev/null
+(ns adventofcode2019.lib
+ [:require [clojure.string :as str]
+ [clojure.java.io :as io]])
+
+(defn get-list-from-file
+ ([file-name]
+ (str/split-lines (str/trim (slurp file-name))))
+ ([file-name split-regex]
+ (str/split (str/trim (slurp file-name)) split-regex)))
+
+(defmacro input-file []
+ (let [bottom-ns (last (str/split (str *ns*) #"\."))]
+ (str "resources/" bottom-ns)))
+
+(def parse-int
+ #(Integer/parseInt %))
--- /dev/null
+(ns adventofcode2019.day00
+ [:require [adventofcode2019.lib :refer :all]
+ [clojure.string :as str]
+ [clojure.math.combinatorics :as combo]])
+
+(defn day00 []
+ (let [input (map parse-int (get-list-from-file (input-file)))]
+ (comment Your code here!)))
--- /dev/null
+(ns adventofcode2019.core-test
+ (:require [clojure.test :refer :all]
+ [adventofcode2019.core :refer :all]))
+
+(deftest a-test
+ (testing "FIXME, I fail."
+ (is (= 0 1))))