--- /dev/null
+/target
+/classes
+/checkouts
+profiles.clj
+pom.xml
+pom.xml.asc
+*.jar
+*.class
+/.lein-*
+/.nrepl-port
+.hgignore
+.hg/
+++ /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
+1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,10,1,19,1,6,19,23,1,23,13,27,2,6,27,31,1,5,31,35,2,10,35,39,1,6,39,43,1,13,43,47,2,47,6,51,1,51,5,55,1,55,6,59,2,59,10,63,1,63,6,67,2,67,10,71,1,71,9,75,2,75,10,79,1,79,5,83,2,10,83,87,1,87,6,91,2,9,91,95,1,95,5,99,1,5,99,103,1,103,10,107,1,9,107,111,1,6,111,115,1,115,5,119,1,10,119,123,2,6,123,127,2,127,6,131,1,131,2,135,1,10,135,0,99,2,0,14,0
--- /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))))