Skip to content

Commit

Permalink
Add 2023 day 9
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFlame14 committed Dec 9, 2023
1 parent 7f651e2 commit 23efe98
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 2023/day9.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(ns clojure-aoc.core (:gen-class)
(:require clojure.string))

(def input (-> (slurp "input.txt") (clojure.string/split #"\n")))

(defn extrapolate [coll back?]
(if (every? #(= % 0) coll)
0
(let [differences (map - (next coll) coll)
ex-next (extrapolate differences back?)]
(if back?
(-> (first coll) (- ex-next))
(-> (last coll) (+ ex-next))))))

(defn oasis-report [back?]
(->> input
(map (fn [line] (map #(Integer/parseInt %) (clojure.string/split line #" "))))
(map #(extrapolate % back?))
(apply +)))

(def part1 (oasis-report false))

(def part2 (oasis-report true))

(defn -main [& args]
(str part1 " " part2))

0 comments on commit 23efe98

Please sign in to comment.