Created
December 24, 2019 01:49
-
-
Save invasionofsmallcubes/b79b21d9e45f07fcaeb58ec4335c6203 to your computer and use it in GitHub Desktop.
Advent Of Code - 2019 - DAY 4 #adventOfCode2019
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
(ns cljbrave.day4) | |
(defn digits | |
[n] | |
(loop [result (list) | |
n n] | |
(if (pos? n) | |
(recur (conj result (rem n 10)) | |
(quot n 10)) | |
result))) | |
(defn adjacent? | |
[n] | |
(true? (reduce (fn [prev v] (if (= prev v) (reduced true) v)) (digits n)))) | |
(defn adjacent-larger? | |
[n] | |
(some #(= 2 (count %)) (partition-by identity (digits n)))) | |
(defn non-decrease? | |
[n] | |
(apply <= (digits n))) | |
(defn possible-password? | |
[n] | |
(and | |
(adjacent? n) | |
(non-decrease? n))) | |
(defn possible-password-enhanced? | |
[n] | |
(and | |
(adjacent-larger? n) | |
(non-decrease? n))) | |
(defn number-of-possible-password | |
[] | |
(count (filter possible-password-enhanced? (range 124075 580770)))) | |
(println (number-of-possible-password)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment