Fork me on GitHub
#code-reviews
<
2020-08-18
>
stopa22:08:29

Hey team, noob one -- my friend and I are following along with sicp in clojure, and did an exercise to implement pascal's triangle:

(defn next-row [last-row]
  (let [sum-neighbor (map-indexed
                       (fn [idx x]
                         (+ x
                            (get last-row
                                 (+ 1 idx)
                                 0)))
                       last-row)]
    (into [1] sum-neighbor)))

(defn pascal [n]
  (condp = n
    0 []
    1 [[1]]
    (let [prev-p (pascal (- n 1))]
      (conj prev-p (next-row (last prev-p))))))
Would be curious to hear if you think there's a more idiomatic clojure way to do this : }