- phase-settings (combo/permutations [0 1 2 3 4])
- all-outputs (for [[a b c d e] phase-settings]
- (do (reset! phase-setting [a 0 b nil c nil d nil e nil nil nil])
- (dotimes [_ 5] (intcode input))
- (last @phase-setting)))]
- (part1 (apply max all-outputs))
- #_(part2 )))
+ phase-settings-1 (combo/permutations [0 1 2 3 4])
+ phase-settings-2 (combo/permutations [5 6 7 8 9])
+ channels (->> #(a/chan 2)
+ (repeatedly 5)
+ (cycle))
+ all-outputs-1 (for [settings phase-settings-1]
+ (do (doall (map a/>!! channels settings))
+ (a/>!! (first channels) 0)
+ (doall (map intcode (repeat 5 input) channels (rest channels)))
+ (a/<!! (first channels))))
+ all-outputs-2 (for [settings phase-settings-2]
+ (do (doall (map a/>!! channels settings))
+ (a/>!! (first channels) 0)
+ (a/<!! (last (for [[prog in out]
+ (map vector (repeat 5 input) channels (rest channels))]
+ (a/thread
+ (intcode prog in out)))))
+ (a/<!! (first channels))))]
+ (part1 (apply max all-outputs-1))
+ (part2 (apply max all-outputs-2))))