Created
December 4, 2020 15:57
-
-
Save stuartstein777/358d08828f25a64223cbd51e822f0256 to your computer and use it in GitHub Desktop.
aoc2020-day2
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
;; part 1 | |
(defn valid? [{:keys [min max c pwd]}] | |
(<= min ((frequencies pwd) c 0) max)) | |
;; part 2 | |
(defn xor [a b] | |
(or (and a (not b)) | |
(and b (not a)))) | |
(defn valid? [{:keys [min max c pwd]}] | |
(let [p1 (nth pwd (dec min) \_) | |
p2 (nth pwd (dec max) \_)] | |
(xor (= c p1) (= c p2)))) | |
;; shared | |
(defn parse-entry [entry] | |
(let [[min max c pwd] (rest (re-find #"(\d+)-(\d+) (.): (.+)" entry))] | |
{:min (Integer/parseInt min) | |
:max (Integer/parseInt max) | |
:c (first c) | |
:pwd pwd})) | |
(->> (slurp "input.txt") | |
(str/split-lines) | |
(map parse-entry) | |
(filter valid?) | |
(count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment