Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
functii recursive
;gnu clisp 2.49.60 ;(print (if t 'yes 'no) ) (defun raport(x y) (if (= y 0) "no divide at 0" (/ x y) ) ) ;(print (raport 10 2) ) ;(print (raport 10 0) ) (defun modul(x) (if (< x 0) (* -1 x) x) ) ;(print (modul 9)) ;(print (modul -19)) (defun semn(x) (if (< x 0) "-" "+") ) ;(print (semn 5)) ;(print (semn -5)) (defun semn2(x) (cond ( (< x 0 ) "-" );conditie 1 ( (= x 0 ) "0" ) ( (> x 0 ) "+" ) );cond );functie ;(print (semn2 7)) ;(print (semn2 -12)) ;(print (semn2 0)) (defun adunare(a b) (if (= a 0) b (adunare (- a 1) (+ b 1) ) ) ) ;(print (adunare 8 2) ) ;(print (trace adunare) ) ;print (adunare 1 21) ) (defun suma3(a b) ;asertie pt a (assert (and (integerp a) (>= a 0) ) (a) "a trebuie sa fie nr natural ~S" a) ;asertie pt b (assert (and (integerp a) (>= a 0) ) (a) "a trebuie sa fie nr natural ~S" a) (if (= a 0) b (adunare (- a 1) (+ b 1) ) ) );defun ;(print (suma3 2 3)) ;(print (suma3 -2 3)) (defun produs(a b) (if (= a 1) b (+ b (produs (- a 1) b)) ) ) ;(print (produs 7 5) ) ;(print (produs 7 2) ) ;ridicarea la putere 2 intregi ne negativi (defun ridicPutere(a b) (assert (and (integerp a) (>= a 0) ) (a) "a trebuie sa fie nr natural ~S" a) ;asertie pt b (assert (and (integerp b) (>= b 0) ) (b) "a trebuie sa fie nr natural ~S" a) (if (= b 0) 1 (* a (ridicPutere a (- b 1) ) ) ) ) ;(print (ridicPutere 2 5) ) ;(print (ridicPutere 3 3) ) (defun llista(lista) (if (null lista) 0 (+ 1 (llista (cdr lista) ) ) ) ) ;(print (llista '(1 2 3 4) ) ) ;(print (llista '(1 2 3 4 6 7 8) ) ) (defun apartineLista(x lista) (cond ( (null lista) 0 ) ( (= x (first lista) ) 1) (t (apartineLista x (cdr lista) ) ) );cond ) ;(print (apartineLista 2 '(4 5 6 8 1 1 1) ) ) ;(print (apartineLista 2 '(4 5 6 8 1 2 1) ) ) (defun doarNumere(lista) (cond ( (null lista) 1 ) ( (not (numberp (first lista) ) ) 0) ;daca e litera putem returna direct ( (numberp (first lista) ) (doarNumere (cdr lista) ) );daca e nr atunci mergem mai departe );cond ) ;(print (doarNumere '(4 5 6 8 1 2 1) ) ) ;(print (doarNumere '(4 5 6 a 1 2 1) ) ) (defun egalListe(l1 l2) (cond ( (and (null l1) (null l2) ) 1 );daca ambele sunt nule => sunt egale ( (or (null l1) (null l2) ) 0) ;daca 1 dintre ele a ajuns primul la null => nu sunt egale ca lungime (t (egalListe (cdr l1) (cdr l2) )) );cond ) ;(trace egalListe) (print (egalListe '(1 2 3 4 5 ) '(5 8 9 9 9) ) ) (print (egalListe '(1 2 3 4 5 ) '(5 8 9 9 9 55) ) )
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Project Euler 265
associativity-test
S17016281_ACTIVIDAD_15
Project Euler Problem 149
removing null elements from the structure list
03_Oliinyk_01
93_Чух_1
L1.9c
t3
lab12
Please log in to post a comment.