everyNth : ('a list) -> int -> ('a list)that will take a list and a positive number i and produce a new list that has every element whose position in the given list is a multiple of i. Some example outputs for the function follow:
# everyNth [1;2;3;4] 2;; - : int list = [2; 4] # everyNth [1;2;3;4] 1;; - : int list = [1; 2; 3; 4] # everyNth [1;2;3;4;5;6] 3;; - : int list = [3; 6] # everyNth [1;2;3;4;5;6] 7;; - : int list = [] #
# everyThird [1; 2; 3; 4; 5];; - : int list = [3] # everyThird [1; 2; 3; 4; 5; 6];; - : int list = [3; 6] # everyThird [];; - : 'a list = [] #
Important: Note again that we need you to define a function with exactly the name and type indicated above.
I used python language to solve
this question.If you have any doubt just ask me.I will explain
you.
In Ocaml Define the function everyNth : ('a list) -> int -> ('a list) that will...
Define a function called collapse() which takes a list as input. Each element of the list will either be an integer, or a list of integers. The function should modify the input list by replacing all of the elements which themselves are lists with the sum of their elements. For example: Test Result vals = [1, 2, 3, 4, 5] collapse(vals) print(vals) [1, 2, 3, 4, 5] vals = [1, [2, 3], 4, 5] collapse(vals) print(vals) [1, 5, 4, 5]...
Write a C++ function, smallestIndex, that takes as parameters an
int array and its size and returns the index of the first
occurrence of the smallest element in the array. To test your
function, write a main that prompts a user for a list of 15
integers and outputs the index and value of the first occurrence of
the smallest value.
The program should print out
Enter 15 integers:
The position of the first occurrence of the smallest element in...
in
ocaml language
Execute > Share main.ml STDIN 2 (* Problem 9. Write a function that takes 3 an integer list and returns the sum of all elements in the list 1.li Result Socamle - main ..ml File "main.ml", line 9, characters 29-37: Error: This expression has type int option but an expression was expected of type int 4 If the list is empty, then return None. *) 5 let rec sum (xs:int list) : int option = 6 (*...
Write a ML language function stripmin of type
int list -> int list that will return a list from which every
instance of the lowest value has been removed.
Hints:
• Only stripmin itself should be visible at the top level;
•You should have two recursive helper functions tucked away
inside a let … in … end; structure
• Also include a val to avoid having to pass a value that never
changes to one of these functions.
• Use...
kind of haskell function ,
In ML, define a function listsquare that when applied to the empty list of integers returns the empty list, and when applied to a non-empty list of integers return a list where each element is squared. For example, listsquares [2, 3, 4] returns [4, 9, 16]. Deine the function using a let expression in ML. val testList = [1, 2, 3, 4, 5] val testResults = listsquare testList
Python 3 Monster = {"name": str, "kind": str, "spookiness": int, "undead?": bool} ''' M5. Define a function `count_spooky_monsters` that consumes a list of monsters and produces an integer indicating how many monsters have a spookiness of 2 or more. ''' ''' M6. Define the function `count_vampires` that consumes a list of monsters and produces an integer indicating how many monsters are of the kind "vampire". '''
Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March","April", "May", "June", "July", "August", "September", days_in_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day number...
Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day...
Problem H1 (Using C++) In the main function, define four variables of type int, named: first, second, third, and total. Write a function named getData that asks the user to input three integers and stores them in the variables first, second, and third which are in the main function. Write a function named computeTotal that computes and returns the total of three integers. Write a function named printAll that prints all the values in the format shown in the following...
Define the get_list_of_lists() function which is passed a list of strings as a parameter. An example parameter list is: ["4 3 1 12 2 12 3 12 4 3", "4 3 1 12 2 12 3 12 4 3", "4 3 1 12 2 6"] The function returns a list of lists of tuples. For each element of the parameter list, e.g., "4 3 1 12 2 12" the function creates a list of tuples, e.g., [("4", 3), ("1", 12),...