]>
Commit | Line | Data |
---|---|---|
1 | (ns adventofcode2019.day04 | |
2 | [:require [adventofcode2019.lib :refer :all] | |
3 | [clojure.string :as str] | |
4 | [clojure.math.combinatorics :as combo]]) | |
5 | ||
6 | (defn find-passwords [low high] | |
7 | (let [dupe-digits #(some (partial apply =) (partition 2 1 %)) | |
8 | increasing (partial apply <=) | |
9 | to-digits #(map int (str %))] | |
10 | (->> (range low (inc high)) | |
11 | (map to-digits) | |
12 | (filter (every-pred dupe-digits increasing))))) | |
13 | ||
14 | (defn day04 [] | |
15 | (let [[low high] [307237 769058] | |
16 | passwords (find-passwords low high) | |
17 | strict-dd (fn [x] (some #(= (count %) 2) | |
18 | (partition-by identity x)))] | |
19 | (part1 (count passwords)) | |
20 | (part2 (count (filter strict-dd passwords))))) |