-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f651e2
commit 23efe98
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |