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]...
*****In SML/NJ****** 1. Write a function count_list with type int list -> int that returns the number of items in a list. An item that is repeated is counted each time it appears in the list. 2. Write an ML function sum_list with type int list -> int that returns the sum of all the elements within a list 3. Write a function countdown with the type int -> int list that returns a list of numbers from its argument...
Python Function Name: networks Parameters: int, list of tuples of int Returns: list of sets of int Description: In your class, many students are friends. Let’s assume that two students sharing a friend must be friends themselves; in other words, if students 0 and 1 are friends and students 1 and 2 are friends, then students 0 and 2 must be friends. Using this rule, we can partition the students into circles of friends. To do this, implement a function...
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
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...
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". '''