Question

Please place all of the following functions (defun …) into a SINGLE .lsp file As such,...

Please place all of the following functions (defun …) into a SINGLE .lsp file

As such, be sure to use the EXACT SAME function names and parameter numbers and orders I provide ​

Write a function ONEFIB that takes a single parameter n and returns the nth Fibonacci number.

Write a function ALLFIB that takes a single parameter n and returns a list of the first n Fibonacci numbers. Do not worry about efficiency here. HINT: You can use ONEFIB to help you here.

Write a function GETELEM that returns that takes two parameters, the first being a list and the second being an integer n, and returns the nth element of that list, whatever it is (list or atom).

Write a function DELELEM that takes 2 parameters, the first being an integer n and the second being a list, and returns a list equivalent to the list passed in with the nth element removed.

Write a function MAXIMUM that takes a simple list of integers as a parameter, and returns the largest (Do not worry about efficiency here).

Write a function COUNTELEMS that returns the number of elements in a list.

Write a function ISPAL that accepts a list as an argument and returns t if the list is a palindrome and nil if it is not. You can assume that each element of the list is a single character atom. HINT: There is a built in function REVERSE that reverses a list.

Write a function FLAT that takes a list as a parameter and breaks all of its’ elements down into atoms, and returns the result (in order). This should also deal with sublists in sublists etc. For example (X Y (Z A) B ((C D E) F)) passed in as the parameter should return (X Y Z A B C D E F).

Please submit a single .lsp file with all of these functions in it. You should test your work on empress.csusm.edu in clisp by loading your file and calling your functions with a variety of different parameters.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Write a function ONEFIB that takes a single parameter n and returns the nth Fibonacci number.

int ONEFIB(int n){
if (n==0){
return 0;
}
else if(n==1){
return 1;
}
else{
return(ONEFIB(n-1) + ONEFIB(n-2)); // it recursively finds nth fibonacci number
}
}

2. Write a function ALLFIB that takes a single parameter n and returns a list of the first n Fibonacci numbers.

int ALLFIB(int n){
   for(int count = 0; count < n; count++){ // recursively finds count'th fibonacci number and prints every number.
return ONEFIB(count)); // we are using ONEFIB(int n) function
}
}

3. Write a function GETELEM that returns that takes two parameters, the first being a list and the second being an integer n, and returns the nth element of that list

int GETELEM(List<Book> books, int n){ //passing list and n as arguments
   List<Book> books = new ArrayList<Book>();   //array list declaration
   int size = books.size(); // to print size of the list
   books.get(n-1); //since array starts with index 0
}

4. Write a function DELELEM that takes 2 parameters, the first being an integer n and the second being a list, and returns a list equivalent to the list passed in with the nth element removed.

int DELELEM(List<Book> books, int n){ //passing list and n as arguments
   List<Book> books = new ArrayList<Book>();   //array list declaration
   int size = books.size(); // to print size of the list
   books.remove(n-1); //since array starts with index 0
   return books;
}

5. Write a function MAXIMUM that takes a simple list of integers as a parameter, and returns the largest.

int MAXIMUM(List<Book> books){ //passing list as an argument
   List<Book> books = new ArrayList<Book>(); //array list declaration
   int max = books.get(0);
   for(int i = 0; i < books.size(); i++) { // comparing every element to get max
n = books.get(i);
if(n < max){
   max = n;
   }
   }
}

6. Write a function COUNTELEMS that returns the number of elements in a list.

int COUNTELEMS(List<Book> books){
   List<Book> books = new ArrayList<Book>(); //array list declaration
   int size = books.size(); // size of list is nothing but the count of elements
   return size;
   }
}

Add a comment
Know the answer?
Add Answer to:
Please place all of the following functions (defun …) into a SINGLE .lsp file As such,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please place all of the following functions (defun …) into a SINGLE .lsp file As such,...

    Please place all of the following functions (defun …) into a SINGLE .lsp file As such, be sure to use the EXACT SAME function names and parameter numbers and orders I provide ​ Write a function ONEFIB that takes a single parameter n and returns the nth Fibonacci number.

  • Write a Python file containing the following functions. Also turn in the output from testing the...

    Write a Python file containing the following functions. Also turn in the output from testing the functions. All arguments to the functions may be hard-coded. Function 1 takes a list of strings as a parameter and returns a list of strings consisting of all the strings in the original list that have identical consecutive letters. For example: fun1 ([llama, good, cat, abba, abab, 112, dog]) returns [llama, good, abba, 112] Function 2 takes an integer (n), representing the number of...

  • Write C++ Code in single source file (.cpp file) containing following user defined functions: 1. IsEven-...

    Write C++ Code in single source file (.cpp file) containing following user defined functions: 1. IsEven- takes an integer input (one argument of type int) and return true or false. 2. IsPositive- takes a float input (one argument of type double) and return a Boolean value. The function returns the true if its argument is positive and false if its argument is zero or negative. 3. IsPrime- takes an integer input and return true or false. 4. NumOfDigits- takes an...

  • C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all...

    C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all the numbers less that the parameter that are divisors of the parameter (i.e. divides it without a remainder) including 1. So printdivisors(6) will print 1,2,3. Note you may use a wrapper function or default parameters. (b) Write a function, sumdixisors, that takes a single integer parameter and returns the sum of all the divisors of the parameter (including 1). So sumdivisors(6) will return 6...

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • python Write a function that takes as input a single integer parametern and computes the nth...

    python Write a function that takes as input a single integer parametern and computes the nth Fibonacci Sequence number The Fibonacci sequence first two terms are 1 and 1(so, if n - 2 your function should return 1). From there, the previous two values are summed to come up with the next result in the sequence 1.1,2,3,5,8,13, 21, 34, 55, etc.) For example, if the input is 7 then your function should return 13 26561.1615880 1 def Fibonacci(n): # your...

  • This is Python coding question, and topic is recursive. Can anyone help me figuring this out?...

    This is Python coding question, and topic is recursive. Can anyone help me figuring this out? (Only recursive function is allowed.) Thanks. Write a function called Fibonacci(n) that takes as a parameter an integer n and returns the nth Fibonacci number. The first two Fibonacci numbers are 1 and every subsequent one is the sum of the previous two: 1, 1, 2, 3, 5, 8, 13, .... Write a recursive function to count the number of uppercase letters in a...

  • in C++ and also each function has its own main function so please do the main...

    in C++ and also each function has its own main function so please do the main function as well. Previously when i asked the question the person only did the function and didn't do the main function so please help me do it. 1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...

  • In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.......

    In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.... In mathematical notation the sequence Fn of Fibonacci number is defined by the following recurrence relation: Fn=Fn-1+Fn-2 With the initial values of F0=0 and F1=1. Thus, the next number in the series is the sum of the previous two numbers. Write a program that asks the user for a positive integer N and generate the Nth Fibonacci number. Your main function should handle user...

  • Write a function, sumdivisors, that takes a single integer parameter and returns the sum of all...

    Write a function, sumdivisors, that takes a single integer parameter and returns the sum of all the divisors of the parameter (including 1). So sumdivisors(6) will return 6 as 1+2+3=6. Note you may use a wrapper function or default parameters.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT