/
day_05.clj
64 lines (53 loc) · 1.43 KB
/
day_05.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(ns advent-of-code-2015.day-05
(:gen-class))
(defn has-three-vowels
[string]
(<= 3 (count (re-seq #"[aeiou]" string))))
(defn has-repeated-letter
[string]
(->> string
(partition 2 1)
(map (partial apply =))
(some identity)))
(defn has-no-naughty-string
[string]
(->> ["ab" "cd" "pq" "xy"]
(map (partial clojure.string/includes? string))
(not-any? identity)))
(defn nice?
[s]
(and (has-three-vowels s)
(has-repeated-letter s)
(has-no-naughty-string s)))
(defn part-1
[input]
(count (filter nice?
(clojure.string/split-lines input))))
(defn has-non-overlapping-pair
[s]
(some identity
(for [i (range 0 (count s))
j (range (+ i 2) (count s))]
(and (= (get s i) (get s j))
(= (get s (inc i)) (get s (inc j)))))))
(defn has-repeated-letter-with-gap
[s]
(some identity
(for [i (range 0 (- (count s) 2))
:when (= (get s i)
(get s (+ i 2)))]
true)))
(defn very-nice?
[s]
(and (has-non-overlapping-pair s)
(has-repeated-letter-with-gap s)))
(defn part-2
[input]
(count (filter very-nice?
(clojure.string/split-lines input))))
(defn day-05
[input-file]
(let [input (slurp input-file)]
(println "Day 5")
(println "Number of nice strings: " (part-1 input))
(println "Number of very nice strings: " (part-2 input))))