I had a thought last night on how I could easily write a Pascal's Triangle generator basically just using
map. I tried writing it this morning, and it got slightly more complicated than I originally thought it would, although it's still pretty nice.
My main concern is the
wrap "hack" that I'm using. I found two similar, but different ways of writing it. I can either wrap the input to the iteration function in 0s, or I can wrap the result of the iteration function in 1s. Both give the same result, but the need for a wrapping helper pollutes an otherwise nice
->> chain. If anyone can think of how I can avoid a separate anonymous function here, and ideally avoid wrapping the input/output in 0s/1s, I'd appreciate it. I'll take any other critique as well, although there isn't much else going on here.
(let [pre-t (pascals-triangle-pre) ; Wrapping pre-processing post-t (pascals-triangle-post) ; Wrapping post-processing n 5] (println (take n pre-t)) (println (take n post-t))) ( [1 1] [1 2 1] [1 3 3 1] [1 4 6 4 1]) ( [1 1] [1 2 1] [1 3 3 1] [1 4 6 4 1])
(ns minesweeper.irrelevant.pas-tri) (defn pascals-triangle-post  (let [wrap #(vec (concat  % ))] (iterate #(->> % (partition 2 1) (mapv (partial apply +')) (wrap)) ))) (defn pascals-triangle-pre  (let [wrap #(vec (concat  % ))] (iterate #(->> % (wrap) (partition 2 1) (mapv (partial apply +'))) )))