Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Lisp function that: given a two-element list, reverse the order of the e

ID: 3625852 • Letter: W

Question

Write a Lisp function that: given a two-element list, reverse the order of the elements in the list (cannot use the LISP reverse function).

Write a Lisp function that given an atom and a list will replace the first element in the list with the single element.
Write a Lisp function that takes as input an atom and a list. The function determines whether any element of the list matches the atom – If it does not match then the first item of the list is replaced with the atom, otherwise the original list is returned.

Write a Lisp function that: given an integer determines whether the integer matches a “held” number. If there is a match it evaluates “OK” otherwise it evaluates “less than” or “greater than” depending on the relationship between the integer and the “held” number.

Write a Lisp function that: computes factorial.

Write a Lisp function that: given an integer “n” generates the first “n” Fibonacci numbers.


Explanation / Answer

(defun fibonacci(n) ; 'Recursive function displays the first n fibonacci numbers
(setq list '()) ; initialize the list
(cond              ; Validate n
       ((= n 1) (setq list1 '(1)))
       ((= n 2) (setq list1 '(1 1)))
              ;adds a number to the beginning of list and reverses list
       ((> n 2) (reverse (push (+ (car (reverse (fibonacci (- n 1)))) (cadr list1)) list1)))))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote