From 1adba42708436a86db1f369028fb6fae4bc4eda8 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 4 Dec 2022 15:14:47 +0200 Subject: Add util fns --- src/aoc_2022/day04.clj | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/aoc_2022/day04.clj') diff --git a/src/aoc_2022/day04.clj b/src/aoc_2022/day04.clj index a6ca91b..bd4d562 100644 --- a/src/aoc_2022/day04.clj +++ b/src/aoc_2022/day04.clj @@ -1,14 +1,14 @@ (ns aoc-2022.day04) +(require '[aoc-2022.utils :refer :all]) (require '[clojure.java.io :as io]) -(require '[aoc-2022.utils :as utils]) (require '[clojure.string :as str]) (defn parse-rows [rows] (->> rows (map #(str/split % #",")) (map (fn [[a, b]] - [(map #(Long/valueOf %) (str/split a #"-")), - (map #(Long/valueOf %) (str/split b #"-"))])) + [(map to-long (str/split a #"-")), + (map to-long (str/split b #"-"))])) (map flatten))) (defn assignment-contains [[a1 a2 b1 b2]] @@ -25,14 +25,15 @@ (defn assignment-overlaps [[a1 a2 b1 b2]] (not (or (> a1 b2) (> b1 a2)))) -(defn task2 [rows] - (->> rows - parse-rows - (filter assignment-overlaps) - count)) +(def task2 + (chain + parse-rows + (partial filter assignment-overlaps) + count)) (with-open [rdr (io/reader "resources/day04_actual.txt")] (let [rows (line-seq rdr)] (do (println "task1:" (task1 rows)) - (println "task2:" (task2 rows))))) + (println "task2:" (task2 rows)) + :done))) -- cgit v1.3