-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04.clj
26 lines (20 loc) · 803 Bytes
/
04.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(ns secure-container
(:require [clojure.string :as str]))
(def password-range (range 367479 (inc 893698)))
(defn never-decreases? [n] (->> (str n) (map #(Integer/parseInt (str %))) (apply <=)))
(defn adjacent-digits? [n] (->> (str n)
(partition-by identity)
(filter #(>= (count %) 2))
seq))
(defn group-of-just-two? [n] (->> (str n)
(partition-by identity)
(filter #(= (count %) 2))
seq))
;; part 1
(->> password-range
(filter (every-pred never-decreases? adjacent-digits?))
count)
;; part 2
(->> password-range
(filter (every-pred never-decreases? group-of-just-two?))
count)