Pascal's triangle/Puzzle: Difference between revisions

Content deleted Content added
No edit summary
revised Clojure version
Line 237: Line 237:
(let [x (solve 1), z (solve 2), y (+ x z)]
(let [x (solve 1), z (solve 2), y (+ x z)]
(println "x =" x ", y =" y ", z =" z))
(println "x =" x ", y =" y ", z =" z))
</lang>
If you want to solve the whole pyramid, just add a call ''(show-pyramid x z)'' to the previous ''let'' form:
<lang lisp>
(defn dot [v1 v2] (reduce + (* v1 v2)))

(defn show-pyramid [x z]
(doseq [row rows]
(println (map #(dot [1 x z] %) row)))
</lang>
</lang>