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.
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;
}
}
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 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- 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 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...
This is Python Coding question. Can anyone help me figuring these out? (Please don't use built-in function, and leave comments for my understanding) Thanks!! 1. Write a function called span(n) that takes as a parameter a 2D list of numbers called n and returns the difference between the largest and smallest number in n. For example, it should return the value 6 for the list [[2, 1, 3],[3, 7, 4]] since the largest number is 7 and the smallest is...
FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, a return will not be allowed! Write and test a function sum_list(nums) Where nums is a...
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...
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...
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...
The normal distribution has parameters μ and σ. The possible values for μ are all numbers on the real line, while σ must be positive. Write an R function that takes in a vector with two elements theta(whose values are unrestricted) and returns a list with two elements. The first element is to represents μ,mu=theta[1], and the second element is to represent σ,sigma=exp(theta[2]). Write a function that takes in a named list for mu and sigma and returns theta.