Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn perform [cycles [op param]] (let [x (peek cycles)] (
- if (= op "noop")
- (conj cycles x)
- (into cycles [x (+ x (Integer/parseInt param))])
- )))
- (defn draw [[screen pos] sprite] (
- if (contains? #{-1 0 1} (- (mod pos 40) sprite))
- [(conj screen "#") (inc pos)]
- [(conj screen ".") (inc pos)]
- ))
- (with-open [rdr (clojure.java.io/reader "cycles.in")] (let [
- lines (->> rdr line-seq (map #(clojure.string/split % #" ")))
- history (reduce perform [1] lines)
- ] (->> history
- (map-indexed vector)
- (filter #(-> % first inc (- 20) (mod 40) zero?))
- (reduce (fn [total [ix x]] (-> ix inc (* x) (+ total))) 0)
- println)
- (->> history
- (reduce draw [[] 0])
- first
- (partition 40)
- (map clojure.string/join)
- (clojure.string/join "\n")
- println)
- ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement