-
-
Save onemouth/984976412306544760f7 to your computer and use it in GitHub Desktop.
POH 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn take-odd [input] | |
(apply str | |
(->> (partition 2 2 nil (apply list input)) | |
(mapcat #(take 1 %))))) | |
(let [line (read-line)] | |
(println (take-odd line))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn calculate-day-sum [lines] | |
(let [parts (partition 7 7 nil lines)] | |
(apply map + parts))) | |
(let [n-input (Integer. (read-line)) | |
lines (for [x (range n-input)] | |
(Integer. (read-line))) | |
day-sum (calculate-day-sum lines)] | |
(doseq [x day-sum] | |
(println x))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as str]) | |
(defn parse-input-line [input-line] | |
(->> (str/split input-line #"\s+") | |
(mapv #(Integer. %)))) | |
(defn empty-table [x y] | |
(for [i (range y)] (vec (take x (repeat false))))) | |
(defn enum-point [x1 y1 x2 y2] | |
(vec (for [x (range x1 (inc x2)) | |
y (range y1 (inc y2))] | |
[x y]))) | |
(defn table-get [table x y] | |
(get-in table [(dec y) (dec x)])) | |
(defn table-set [table x y v] | |
(assoc-in table [(dec y) (dec x)] v)) | |
(defn sum-points [table flag-table points] | |
(loop [sum 0 table table flag-table flag-table points points] | |
(if-let [point (first points)] | |
(if (= false (apply table-get flag-table point)) | |
(recur (+ sum (apply table-get table point)) | |
table | |
(table-set flag-table (get point 0) (get point 1) true) | |
(rest points)) | |
(recur sum table flag-table (rest points))) | |
sum))) | |
(let [[x y n] (parse-input-line (read-line)) | |
table (vec (for [i (range y)] (parse-input-line (read-line)))) | |
flag-table (vec (empty-table x y)) | |
points (for [i (range n)] (apply enum-point (parse-input-line (read-line)))) | |
points-cat (mapcat identity points)] | |
(println (sum-points table flag-table points-cat))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment