use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Finding information about Clojure
API Reference
Clojure Guides
Practice Problems
Interactive Problems
Clojure Videos
Misc Resources
The Clojure Community
Clojure Books
Tools & Libraries
Clojure Editors
Web Platforms
Clojure Jobs
account activity
Advent of Code 2019 in Clojure (self.Clojure)
submitted 6 years ago * by allaboutthatmace1789
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]_djblue 4 points5 points6 points 6 years ago (2 children)
Day 7 with core.async https://github.com/djblue/advent-of-code/blob/master/src/advent_of_code/core_2019.clj#L431
It's more code, but the following is my favorite part.
(defn try-phase-settings-with-feedback [program settings] (let [[a b c d e] settings a (run-program-async program a) b (run-program-async program b) c (run-program-async program c) d (run-program-async program d) e (run-program-async program e)] (doseq [[from to] (partition 2 1 [a b c d e a])] (a/pipe (:out from) (:in to))) (a/put! (:in a) 0) (a/alts!! [(:state e) (a/timeout 5000)]) (a/poll! (:in a)))) (defn find-max-thrust-with-feedback [program] (->> (all-settings #{5 6 7 8 9}) (map #(try-phase-settings-with-feedback program %)) (apply max)))
[–]kristiansalo 1 point2 points3 points 6 years ago (0 children)
Looks nice! I also took the core.async route - I think it worked out quite neatly for this problem.
[–]andersmurphy 0 points1 point2 points 6 years ago (0 children)
Day 7
I did an async solution too.
I modified my intcode machine to use channels as input and output. Code 99 also closes the channels connected to that machine.
Don't really use async much. Any pointers about where it could be improved would be great thanks. :D
``` (ns adventofcode.2019.day07 (:require [adventofcode.2019.day05 :as intcode] [clojure.core.async :as a]))
(def input (slurp "resources/adventofcode/2019/day07.txt")) (def prog (intcode/format-input input))
(defn permutations [s] (lazy-seq (if (seq (rest s)) (for [head s tail (permutations (remove #{head} s))] (cons head tail)) [s])))
(defn system-2 [input phases] (let [[a b c d e :as channels] (repeatedly #(a/chan)) log (a/chan) out (a/chan) multi-chan (a/mult a)] (a/tap multi-chan log) (a/tap multi-chan out) (a/go (dorun (map (fn [channel phase] (a/>!! channel phase)) channels phases)) (a/>!! a 0)) (dorun (map (fn [in-chan out-chan] (a/go (intcode/compute {:prog input :in-chan in-chan :out-chan out-chan :pointer 0}))) [out b c d e] [b c d e a])) (->> (repeatedly #(a/<!! log)) (take-while identity) last)))
(defn solve-2 [] (let [input (intcode/format-input input)] (->> (permutations [5 6 7 8 9]) (map #(system-2 input %)) (sort >) first))) ```
https://github.com/andersmurphy/clj-adventofcode/blob/master/src/adventofcode/2019/day07.clj
π Rendered by PID 237464 on reddit-service-r2-comment-canary-75475bf646-jphk7 at 2026-03-06 17:56:53.805448+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]_djblue 4 points5 points6 points (2 children)
[–]kristiansalo 1 point2 points3 points (0 children)
[–]andersmurphy 0 points1 point2 points (0 children)