Last active
December 2, 2021 16:20
-
-
Save pradeepbishnoi/5e1a6fe2ab5c0d5f0e651935185e1b97 to your computer and use it in GitHub Desktop.
Advent Of Code 2021 - Clojure Solutions
This file contains hidden or 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
;; Advent Of Code 2021 | |
;; Author : Pradeep Bishnoi | |
;; Solution for Problem 1a and 1b | |
;; Done via REPL, will polish them sooner. | |
(def depth '(199 200 208 210 200 207 240 269 260 263)) | |
(def depth-file | |
(clojure.string/split-lines (slurp "/tmp/advent/1a.txt"))) | |
(defn tuple-compare [tuple] | |
;; tuple = (199, 200) | |
(when (< (first tuple) | |
(last tuple)) | |
true)) | |
(defn sum-my-tuple [tuple] | |
(apply + tuple)) | |
;; Solution for 1a | |
(->> depth-file | |
(map #(Integer/parseInt %)) | |
(partition 2 1) ;; ((199 200) (200 208) (208 210) (200 207) ...) | |
(filter tuple-compare) | |
count) | |
;; Solution for 1b | |
(->> depth-file | |
(map #(Integer/parseInt %)) | |
(partition 3 1) ;; ((199 200 208) (200 208 210) (208 210 200) ...) | |
(map sum-my-tuple) ;; (607 618 618 617 647 ...) | |
(partition 2 1) ;; ((607 618) (617 647) (647 716) (716 769) ...) | |
(filter tuple-compare) | |
count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yes, valid point.