Pascal's triangle: Difference between revisions

Content added Content deleted
No edit summary
(Emacs Lisp -- Pascal's triangle)
Line 1,889: Line 1,889:
[1, 6, 15, 20, 15, 6, 1]
[1, 6, 15, 20, 15, 6, 1]
[1, 7, 21, 35, 35, 21, 7, 1]
[1, 7, 21, 35, 35, 21, 7, 1]
</pre>

=={{header|Emacs Lisp}}==
<lang lisp>(defun next-row (row)
(mapcar* #'+ (cons 0 row)
(append row '(0))))

(defun triangle (row rows)
(if (= rows 0)
'()
(cons row (triangle (next-row row) (- rows 1)))))
</lang>

{{Out}}
Call the function from the REPL, IELM:
<pre>
ELISP> (triangle (list 1) 6)
((1)
(1 1)
(1 2 1)
(1 3 3 1)
(1 4 6 4 1)
(1 5 10 10 5 1))
</pre>
</pre>