diff options
author | Oscar Najera <hi@oscarnajera.com> | 2023-02-05 19:09:06 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2023-02-05 19:09:06 +0100 |
commit | 4daf41bd69e01f137be90881ec419b3c045a2ec5 (patch) | |
tree | cc69c4dcc980c304e8e12ce11485533c0011f1f5 | |
parent | 84ec86b63ac38423ce021448e379b87094f7d4ac (diff) | |
download | scratch-4daf41bd69e01f137be90881ec419b3c045a2ec5.tar.gz scratch-4daf41bd69e01f137be90881ec419b3c045a2ec5.tar.bz2 scratch-4daf41bd69e01f137be90881ec419b3c045a2ec5.zip |
Try clojure for day 1 and test transducers
-rw-r--r-- | AoC2022/aocclj/.gitignore | 13 | ||||
-rw-r--r-- | AoC2022/aocclj/project.clj | 10 | ||||
-rw-r--r-- | AoC2022/aocclj/src/aocclj/core.clj | 8 | ||||
-rw-r--r-- | AoC2022/aocclj/src/aocclj/day01.clj | 18 | ||||
-rw-r--r-- | AoC2022/aocclj/test/aocclj/core_test.clj | 7 | ||||
-rw-r--r-- | AoC2022/aocclj/test/aocclj/day01_test.clj | 10 |
6 files changed, 66 insertions, 0 deletions
diff --git a/AoC2022/aocclj/.gitignore b/AoC2022/aocclj/.gitignore new file mode 100644 index 0000000..d956ab0 --- /dev/null +++ b/AoC2022/aocclj/.gitignore @@ -0,0 +1,13 @@ +/target +/classes +/checkouts +profiles.clj +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port +/.prepl-port +.hgignore +.hg/ diff --git a/AoC2022/aocclj/project.clj b/AoC2022/aocclj/project.clj new file mode 100644 index 0000000..d17ed4c --- /dev/null +++ b/AoC2022/aocclj/project.clj @@ -0,0 +1,10 @@ +(defproject aocclj "0.1.0-SNAPSHOT" + :description "FIXME: write description" + :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.11.1"]] + :main ^:skip-aot aocclj.core + :target-path "target/%s" + :profiles {:uberjar {:aot :all + :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}}) diff --git a/AoC2022/aocclj/src/aocclj/core.clj b/AoC2022/aocclj/src/aocclj/core.clj new file mode 100644 index 0000000..35a8acb --- /dev/null +++ b/AoC2022/aocclj/src/aocclj/core.clj @@ -0,0 +1,8 @@ +(ns aocclj.core + (:gen-class) + (:require [clojure.string :as str])) + +(defn -main + "I don't do a whole lot ... yet." + [& args] + (println "Hello, World!")) diff --git a/AoC2022/aocclj/src/aocclj/day01.clj b/AoC2022/aocclj/src/aocclj/day01.clj new file mode 100644 index 0000000..8fca2e6 --- /dev/null +++ b/AoC2022/aocclj/src/aocclj/day01.clj @@ -0,0 +1,18 @@ +(ns aocclj.day01 + (:require [clojure.string :as str])) + +(defn preprocess [input] + (transduce + (comp + (map parse-long) + (partition-by nil?) + (take-nth 2) + (map (partial reduce +))) + conj + input)) + +(defn part1 [input] + (apply max (preprocess input))) + +(defn part2 [input] + (->> input preprocess sort (take 3) (apply +))) diff --git a/AoC2022/aocclj/test/aocclj/core_test.clj b/AoC2022/aocclj/test/aocclj/core_test.clj new file mode 100644 index 0000000..15216e7 --- /dev/null +++ b/AoC2022/aocclj/test/aocclj/core_test.clj @@ -0,0 +1,7 @@ +(ns aocclj.core-test + (:require [clojure.test :refer :all] + [aocclj.core :refer :all])) + +(deftest a-test + (testing "FIXME, I fail." + (is (= 1 1)))) diff --git a/AoC2022/aocclj/test/aocclj/day01_test.clj b/AoC2022/aocclj/test/aocclj/day01_test.clj new file mode 100644 index 0000000..ca1262c --- /dev/null +++ b/AoC2022/aocclj/test/aocclj/day01_test.clj @@ -0,0 +1,10 @@ +(ns aocclj.day01-test + (:require [aocclj.day01 :as sut] + [clojure.test :as t] + [clojure.string :as str])) + +(t/deftest solutions + (let [input (str/split-lines (slurp "../01/input"))] + (t/are [expected function] (= expected (function input)) + 75622 sut/part1 + 213159 sut/part2))) |