Jump to content

Pascal's triangle/Puzzle: Difference between revisions

revised Clojure version
No edit summary
(revised Clojure version)
Line 237:
(let [x (solve 1), z (solve 2), y (+ x 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>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.