Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,13 @@
(defun pascal (n)
(genrow n '(1)))
(defun genrow (n l)
(when (plusp n)
(print l)
(genrow (1- n) (cons 1 (newrow l)))))
(defun newrow (l)
(if (null (rest l))
'(1)
(cons (+ (first l) (second l))
(newrow (rest l)))))

View file

@ -0,0 +1,12 @@
(defun pascal-next-row (a)
(loop :for q :in a
:and p = 0 :then q
:as s = (list (+ p q))
:nconc s :into a
:finally (rplacd s (list 1))
(return a)))
(defun pascal (n)
(loop :for a = (list 1) :then (pascal-next-row a)
:repeat n
:collect a))

View file

@ -0,0 +1,16 @@
(defun next-pascal-triangle-row (list)
`(1
,.(mapcar #'+ list (rest list))
1))
(defun pascal-triangle (number-of-rows)
(loop repeat number-of-rows
for row = '(1) then (next-pascal-triangle-row row)
collect row))
(defun print-pascal-triangle (number-of-rows)
(let* ((triangle (pascal-triangle number-of-rows))
(max-row-length (length (write-to-string (first (last triangle))))))
(format t
(format nil "~~{~~~D:@<~~{~~A ~~}~~>~~%~~}" max-row-length)
triangle)))

View file

@ -0,0 +1 @@
(print-pascal-triangle 4)

View file

@ -0,0 +1,4 @@
1
1 1
1 2 1
1 3 3 1

View file

@ -0,0 +1 @@
(print-pascal-triangle 8)

View file

@ -0,0 +1,8 @@
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1