-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03.clj
39 lines (33 loc) · 803 Bytes
/
03.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
(ns adventofcode2022.03
(:require [clojure.string :as s]
[clojure.set :as set]))
(defn getCommon
[strInput]
(let [[bag1 bag2] (#(split-at (/ (count %) 2) %) strInput)]
(set/intersection (set bag1) (set bag2))))
(defn getValue
[char]
(let [charInt (int char)]
(if (and (>= charInt (int \a) )
(<= charInt (int \z) ))
(- charInt 96)
(+ 26 (- charInt 64 )))))
(defn solve1
[]
(->> (slurp "./03-input.txt")
(s/split-lines)
(map getCommon)
(map first)
(map getValue)
(apply +)))
(defn solve2
[]
(->> (slurp "./03-input.txt")
(s/split-lines)
(partition 3)
(map #(map set %))
(map #(apply set/intersection %))
(map first)
(map getValue)
(apply +)))
(solve2)