]>
Commit | Line | Data |
---|---|---|
0503903a JK |
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 [] | |
b49567e7 JK |
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)))] | |
0503903a | 19 | (part1 (count passwords)) |
b49567e7 | 20 | (part2 (count (filter strict-dd passwords))))) |