diff options
Diffstat (limited to 'day-02')
-rw-r--r-- | day-02/.gitkeep | 0 | ||||
-rw-r--r-- | day-02/sol.clj | 34 |
2 files changed, 0 insertions, 34 deletions
diff --git a/day-02/.gitkeep b/day-02/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/day-02/.gitkeep +++ /dev/null diff --git a/day-02/sol.clj b/day-02/sol.clj deleted file mode 100644 index 99783cc..0000000 --- a/day-02/sol.clj +++ /dev/null @@ -1,34 +0,0 @@ -(require '[clojure.java.io]) - -(defn find-recurring-characters [strs] - (reduce (fn [a x] - (into #{} (filter #(contains? a %) x))) - (into #{} (first strs)) - strs)) - -(defn get-priority [c] - (if (>= c 97) - (- c 96) - (- c 38))) - -(defn obtain-total-priorities [rucksacks] - (reduce + (map (fn [line] - (let [half (/ (count line) 2)] - (get-priority (int - (first (find-recurring-characters - (list (subs line 0 half) - (subs line half)))))))) - rucksacks))) - -(defn obtain-total-priorities-2 [rucksacks] - (reduce + (map (fn [lines] - (get-priority (int (first (find-recurring-characters lines))))) - (partition 3 rucksacks)))) - -(defn main [] - (with-open [rdr (clojure.java.io/reader "input")] - (println (obtain-total-priorities (line-seq rdr)))) - (with-open [rdr (clojure.java.io/reader "input")] - (println (obtain-total-priorities-2 (line-seq rdr)))) - (System/exit 0)) -(main)
\ No newline at end of file |