Skip to content

Instantly share code, notes, and snippets.

View piyushmaurya23's full-sized avatar

Piyush Maurya piyushmaurya23

  • London, United Kingdom
View GitHub Profile
@piyushmaurya23
piyushmaurya23 / list_append.lisp
Last active October 31, 2017 20:58
7. Define a Recursive LISP function which takes one argument as a list and returns reverse of the list. (do not use reverse predicate)
(defun list_append(l1 l2)
(if (null l1)
l2
(cons (first l1)(list_append (rest l1) l2))))
@piyushmaurya23
piyushmaurya23 / remove.lisp
Created October 16, 2015 21:02
8. Define a Recursive LISP function which takes two arguments first, an atom, second, a list, returns a list after removing first occurrence of that atom within the list.
(defun remov(elt lst)
(cond ((null lst) nil)
((equal elt (first lst))(rest lst))
(elt (cons (first lst)(remov elt (rest lst))))))
@piyushmaurya23
piyushmaurya23 / exceptlast_list.lisp
Last active October 16, 2015 20:23
6. Define a Recursive LISP function which takes one argument as a list and returns a list except last element of the list. (do not use but last predicate)
(defun exceptlast_element(user_list)
(reverse (cdr (reverse user_list))))
@piyushmaurya23
piyushmaurya23 / last_list.lisp
Last active October 16, 2015 20:21
5. Define a Recursive LISP function which takes one argument as a list and returns last element of the list. (do not use last predicate)
(defun last_element(user_list)
(car (reverse user_list)))
@piyushmaurya23
piyushmaurya23 / factorial.lisp
Last active November 13, 2018 16:41
4. Define a Recursive LISP function to compute factorial of a given number.
(defun fact(n)
(if (= n 1)
1
(* n (fact (- n 1)))))
@piyushmaurya23
piyushmaurya23 / akerman.lisp
Last active October 16, 2015 20:28
3. Define a Recursive LISP function to solve Ackermann’s Function.
(defun akermann(m n)
(cond
((= m 0) (+ n 1))
((and (> m 0) (= n 0)) (akermann (- m 1) 1))
((and (> m 0) (> n 0)) (akermann (- m 1) (akermann m (- n 1))))))
@piyushmaurya23
piyushmaurya23 / square_diff.lisp
Last active October 16, 2015 20:26
2. Define a LISP function to compute difference of squares. (if x > y return x 2 -y 2 , otherwise y 2 - x 2 ).
(defun square_diff(x y)
(if (> x y)
(- (* x x) (* y y))
(- (* y y) (* x x))))
@piyushmaurya23
piyushmaurya23 / square_sum.lisp
Last active October 16, 2015 20:24
1. Define a LISP function to compute sum of squares.
(defun square_sum(x y)
(+ (* x x) (* y y)))