Question
Please complete the following programming in LISP with clear explanations. Thanks! Code the following functions in a single lisp file named homework.lisp. 1. add (number
Please complete the following programming in LISP with clear explanations. Thanks!
Code the following functions in a single lisp file named homework.lisp. 1. add (number number) Write a function named add that takes two numbers as parameters and returns the sum of the two numbers. 2. minimum (list) Write a function named minimum that takes a list of numbers as a parameter. Search the entire list and return the smallest value from the list. 3. average (list) Write a function named average that takes a list of numbers as a parameter. Return the average of all numbers in the list. 4. count-of (symbol list) Write a function named count-of that takes two parameters, a symbol and a list. Count the number of instances of x in the list. Do not count the number of x in any sub-lists within the list. 5. iterative-factorial (number) Write an iterative function that calculates the factorial of a positive integer and return the result. The function should be equivalent to this Java code. public static double iterative-factorial (double n) {
double sum = 1;
for (double i=0; i < n; i++)
sum = sum * (1 + i);
return sum;
} 6. recursive-factorial (number) Write a recursive function that calculates the factorial of a positive integer and return the result. The function should be equivalent to this Java code. public static double recursive-factorial (double n) {
if (n<=1)
return 1;
else
return n * recursive-factorial (n-1);
} 7. fibonacci (number) Write a function named fibonacci that takes a number, n, as a parameter. Return the nth number in the Fibonacci sequence. Use the following definition of the fibonnaci sequence:
()={0 =0 1 =1 (1)+(2)
8. trim-to (symbol list) Write a function named trim-to that takes a symbol and list as parameters. Return a new list starting from the first occurrence of the input symbol in the input list. If there is no occurrence of the symbol, return nil. For example:
(trim-to c (a b c d e))
This should return the following list:
(c d e) 9. ackermann (number number) Write a function named ackermann that takes two integers. Use the following function definition: (Note: due to this functions complexity it may not finish for inputs larger than 3)
(,)={+1 =0 (1,1) =0 (1,(,1))
10. Copy and paste the following code at the end of your file. (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) Sample Output:
4
5
3
2
120
24
8
(C D E)
3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started