Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
LISP Funcs
;gnu clisp 2.49.60 ;(defun f1 (lst el) ; (cond ; ((null lst) nil) ; ((listp (car lst)) (cons (f1 (car lst) el) (f1 (cdr lst) (+ (car (f1 (car lst) el)) 1)))) ; (t (cons el (f1 (cdr lst) (+ el 1)))))) ; ; ;(print ; (f1 '(A (B) (C D) F E) 0) ;) ; ЛР 5, 1 (defun lstLength (lst) (cond ((null lst) 0) (t (+ 1 (lstLength (cdr lst)))) ) ) ; ЛР 5, 2 (defun isMember (n lst) (cond ((null lst) NIL) ((atom (car lst)) (cond ((eq (car lst) n) T) (t (isMember n (cdr lst))) ) ) (t (cond ((isMember n (car lst)) T) (t (isMember n (cdr lst))) ) ) ) ) ; ЛР 5, 3 (defun fibonacciNum (n) (cond ((eq n 0) 0) ((eq n 1) 1) (t (+ (fibonacciNum (- n 1)) (fibonacciNum (- n 2)))) ) ) ; ЛР 5, 4 (defun invers (lst) (cond ((null lst) ()) (t (append (invers (cdr lst)) (list (car lst)))) ) ) ; ЛР 5, 5 (defun makeList (n x) (cond ((eq n 0) ()) ((eq n 1) (list x)) (t (cons x (makeList (- n 1) x))) ) ) ; ЛР 6, 6 ;(listElSum '(() 15 (5) (11 (())))) (defun listElSum (lst) (cond ((null lst) 0) ((atom (car lst)) (cond ((null (car lst)) (+ 0 (listElSum (cdr lst)))) (t (+ (car lst) (listElSum (cdr lst)))) ) ) (t (+ (listElSum (car lst)) (listElSum (cdr lst)))) ) ) ; ЛР 6, 1 (defun floatSum (lst) (cond ((null lst) 0) ((atom (car lst)) (cond ((floatp (car lst)) (+ (car lst) (floatSum (cdr lst)))) (t (floatSum (cdr lst))) ) ) (t (+ (floatSum (car lst)) (floatSum (cdr lst)))) ) ) ; ЛР 6, 2 (defun isRepeat (el lst) (cond ((null lst) NIL) ((eq el (car lst)) t) (t (isRepeat el (cdr lst))) ) ) (defun lstInverse (lst) (cond ((null lst) ()) ((listp (car lst)) (append (lstInverse (cdr lst)) (lstInverse (car lst)))) ((isRepeat (car lst) (cdr lst)) (append (lstInverse (cdr lst)) ())) (t (append (lstInverse (cdr lst)) (list (car lst)))) ) ) ; ЛР 6, 4 (defun takeNeg (lst) (cond ((null lst) ()) (t (cond ((< (car lst) 0) (cons (car lst) (takeNeg (cdr lst)))) (t (takeNeg (cdr lst))) ) ) ) ) (defun takePos (lst) (cond ((null lst) ()) (t (cond ((> (car lst) 0) (cons (car lst) (takePos (cdr lst)))) (t (takePos (cdr lst))) ) ) ) ) (defun NegPos (lst) (append (takeNeg lst) (takePos lst))) ; Бонус, 3 (defun romAnalog (n) (cond ((eq n 1) 'I) ((eq n 2) 'II) ((eq n 3) 'III) ((eq n 4) 'IV) ((eq n 5) 'V) ((eq n 6) 'VI) ((eq n 7) 'VII) ((eq n 8) 'VIII) ((eq n 9) 'IX) (t ()) ) ) (defun chToRom (lst) (cond ((null lst) ()) (t (cons (romAnalog (car lst)) (chToRom (cdr lst)))) ) ) ; Бонус, 5 (defun delRepeatNeighbor (lst) (cond ((null lst) ()) ((listp (car lst)) (append (delRepeatNeighbor (car lst)) (delRepeatNeighbor (cdr lst))) ) (t (cond ((eq (car lst) (cadr lst)) (append () (delRepeatNeighbor (cdr lst)))) (t (cons (car lst) (delRepeatNeighbor (cdr lst)))) ) ) ) ) ; Бонус, 6 (defun square (lst) (cond ((null lst) ()) ((listp (car lst)) (append (square (car lst)) (square (cdr lst)))) (t (cons (* (car lst) (car lst)) (square (cdr lst)))) ) ) ; ЛР 6, 3, Not complete (defun numOfSymb (el lst) (cond ((null lst) 1) (t (cond ((eq el (car lst)) 1) (t (+ 1 (numOfSymb el (cdr lst)))) ) ) ) ) (defun numInsteadSym (lst) (cond ((null lst) ()) (() ()) ) ) (print (numInsteadSym '(a b b c f g)) )
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
L1.9b
Szu_Test
L1.8d
Реализация нахождения числа Фибоначчи... на лиспе.
Recursao
max element
maio de 3
fibonacci with cond
HW5
lr_1
Please log in to post a comment.