Skip to content

Commit bdbe0df

Browse files
committed
finish part 2 of 2 of 2020
1 parent 744d2e2 commit bdbe0df

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

2020/2/script.cljs

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333
letter-frequency (get frequencies letter)]
3434
(and (>= letter-frequency min) (<= letter-frequency max))))
3535

36+
(defn- validate-password-position
37+
[condition-password]
38+
(let [password (:password condition-password)
39+
min (get-in condition-password [:condition :min])
40+
max (get-in condition-password [:condition :max])
41+
letter (get-in condition-password [:condition :letter])
42+
letter-at-min-match (= letter (nth password (- min 1)))
43+
letter-at-max-match (= letter (nth password (- max 1)))]
44+
(and (or letter-at-min-match letter-at-max-match) (not (and letter-at-min-match letter-at-max-match)))))
45+
3646
(def frequency-validity (map #(validate-password-frequency (parse-line %)) input))
3747

48+
(def position-validity (map #(validate-password-position (parse-line %)) input))
49+
3850
(count (filter #(identity %) frequency-validity))
51+
(count (filter #(identity %) position-validity))

0 commit comments

Comments
 (0)