Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Homework.lisp
(defun add (x y) ( + x y) ) (defun minimum (list) (cond ((null list) nil) ((null (rest list)) (first list)) ((< (first list) (second list)) (minimum (cons (first list) (rest (rest list))))) (t (minimum (rest list))) ) ) (defun average (list) (when list (/ (reduce #'+ list) (list-length list)) ) ) (defun count-of (symbol lst) (if (null lst) 0 (if (equal (car lst) symbol) (+ 1 (count-of symbol (cdr lst))) (count-of symbol (cdr lst)) ) ) ) (defun iterative-factorial (n) (let ((sum 1)) (dotimes (i n) (setf sum (* sum (+ i 1)))) sum ) ) (defun recursive-factorial (n) (if (<= n 1) 1 (* n (recursive-factorial(1- n))))) (defun fibonacci (N) (if (= 0 N) 0 (if (= 1 N) 1 (+ (fibonacci (- N 1)) (fibonacci (- N 2)))))) (defun trim-to(symbol l) (if (null l) l (if (equal (car l) symbol) l (trim-to symbol (cdr l)) ) ) ) (defun ackermann (x y) (cond ((= x 0) (+ y 1)) (t (cond ((= y 0) (ackermann (- x 1) 1)) (t (ackermann (- x 1) (ackermann x (- y 1)))) )) )) (defun test() (print (add 3 1)) (print (average '(1 2 3 4 5 6 7 8 9))) (print (minimum '(5 78 9 8 3))) (print (count-of 'a '(a '(a c) d c a))) (print (iterative-factorial 5)) (print (recursive-factorial 4)) (print (fibonacci 6)) (print (trim-to 'c '(a b c d e))) (print (ackermann 1 1))) (test)
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
2rec
iiiiiiiiiiiiii
504
Basic Input/Output
FP-LABS-0
PE 162
Q7-B
CMSC 257 Revised Assignment 4
hihi
Lab1
Please log in to post a comment.