From 897410ff8148cda1d9742213b7f775dbb6f55238 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 3 Dec 2021 09:20:32 -0500 Subject: add day3 --- day3/part1.clj | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 day3/part1.clj (limited to 'day3/part1.clj') diff --git a/day3/part1.clj b/day3/part1.clj new file mode 100644 index 0000000..3c09ff8 --- /dev/null +++ b/day3/part1.clj @@ -0,0 +1,33 @@ +(def counts + (loop [line (read-line) + tot (repeat (count line) 0) + ] + (if (empty? line) + tot + (recur + (read-line) + (map + tot (map #(if (= % \1) 1 0) line)) + ) + ) + ) + ) + +(println counts) + +(loop [cnts counts gamma 0 epsilon 0] + (if (empty? cnts) + (println (* gamma epsilon)) + (recur + (rest cnts) + (if (> (first cnts) 500) + (inc (* 2 gamma)) + (* 2 gamma) + ) + (if (< (first cnts) 500) + (inc (* 2 epsilon)) + (* 2 epsilon) + ) + ) + ) + ) + -- cgit v1.2.3