-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3.clj
34 lines (29 loc) · 10.3 KB
/
day3.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
(ns aoc.day3
[:require [clojure.string :as str]
[clojure.set :as set]])
(def input "QJRBMDMtRDCtJzBtJMfjNjhwvmNDvwjLVVgh\nTPSNNPZGTjgmSmvfjL\nbPlpZZbpsTlTsWprpGFCJtRtzMNdMMBBcWnJQB\ntppvbQBhpQQdrzMMcLwhMc\ngZnWRccRNgFGRGRFRNNgZgJMddddLLLMCPqwLCNPwqPJ\nnRRmFSnWmlgZlTlTllSlSWWWTsfvfDQpBfBcpQvpVQpTfQQf\nlRlsVFgTlMgRNsSNTlFgmbWnMPppPnMqWZMWPPWW\nfDjgBJdCfCHHBnfLWpqnmnpZmf\nGjQHHcdvJHQBHSSNsFQFslwwRg\nNPwDLDHNwjLLHWjbdSbDfJJQTZsZDS\nBcFBcvgFvghnFLrBpvrgcgrJSZJpQdfSTZbCsSdfZZfbCf\nVrngVFRmrVWHLGVMlL\nSNBBBDlfZDLqNGmgFjjmBsQgCFtF\nVPPVbhpbhMhRhncnScRncbrQtCgQQFmjjjsgtRtQHmFQ\nnhWcPJVhpbvMvwvwllvSlGlD\nwNlNNqtqHHHPhqCz\nMMMMcQSWSpQCWFnRRPchLVvPLLzhmhLzhh\nCrgRSWrnrQpppRQrCTnRTRtGtBDBfbNBllbTJlZtfNBN\nQNbbNrnNnCwHmNPQmzqQNPsCCfBFFGtsBBddBDtCJDJd\ngvVgpZWgTWvRvlvLPDDJjGBfdsdpDDJGdd\nZRMWWRMVgRZghTggPSMZzQwwnqwmnzhNnNwHcQHm\nVmPHzBmpmQHbVHSpNHBVQCtRPPCPvFFMqqntZCZqMR\ndWlDcfcfcjcfDWjlsZfjJhdGvFLGnLsLqsRnvRvRGGRttC\nwfJhZTllcfdZdfjJfjdmQzHVSzHzgHQTpHpmp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MjCpTpj\nrQdZfhzczNzWcNLTpWgSvjjjpGpMSB\nZqNDQhfcNchLchQqcDqRHJtHVwnwbtvHsbVs\nqtJGQgTrqtqQdQDgbGjPzZHWWzVjslPZlG\nvBShwRRvvSRSvFvwLSvfcnfBWmHZHVWWHPzlNPWVWjZsWnWV\ncLBFBFhCBLlwpFccFBFftqJDQdgdTDJJCbJgCCdg\nwfmsPvPwNfvmfLNFvzzJbRMnllhlnLhRLC\ngjtqDDTtjgpJcbnMTzCRnCCWhC\nSDqtpGSStVtdqpgBVjBGZmFPJNJmffvfPsHZPZQd\nHQMBBWrQQmPBvmBWnvrTnMSsbFfcfwgfCgscsmGgwgcJGg\nNzzlJLthtlgswGFcwGst\nJqNNRqpzhVRWTSQrrvSQ\nmFpDZjvmtPPGvFjmmGTzTcFRbHczHTbzQgRS\nfNdqhJsNrnnVNhwNVdrdsVczQCcwCMHSTCHgHCRzHgcM\nJlgnNhsqVqNqNpPlvZvDDDGlZZ\n")
(defn parse-input [input]
(str/split input #"\n"))
(defn priority [item]
(let [n (int item)]
(cond
(<= 97 n 122) (- n 96)
(<= 65 n 90) (- n 38))))
(defn part1 []
(->>
(parse-input input)
(map #(split-at (/ (count %) 2) %))
(map (partial map set))
(map (partial apply set/intersection))
(map first)
(map priority)
(reduce +)))
(defn part2 []
(->>
(parse-input input)
(partition 3)
(map (partial map set))
(map (partial apply set/intersection))
(map first)
(map priority)
(reduce +)))