Define a function in SML, called "less" of type int * int list -> int list so that less(e,L) is a list of all the integers in L that are less than e.


/* Lets Describing a function member of type ''a ''a list ->
bool
so that member(e, L) is true if and only if e is an element of the
given list L. *)
(/* Correct, but non-pattern matching version is :
fun member (e, L) =
if null L
then false
else if e = hd(L)
then true
else member (e, tl(L));
/*)
fun member (e, nil) = false
| member (e, y::ys) = if (e=y)
then true
else member(e, ys);
member (1, []);
member (1, [1, 2]);
member (1, [2, 1, 3]);
member (1, [2, 3]);
(/ Describing a function less of type int int list -> int
list
so that less (e, L) is a list of all the integers in L that
are less than e
/*)
(*/ Correct, but non-pattern matching version:
fun less (e, L) =
if null L
then nil
else if hd(L) < e
then hd(L) :: less(e, tl(L))
else less (e, tl(L));
*)
fun less (e, nil) = nil
| less (e, y::ys) = if y < e
then y :: less(e, ys)
else less (e, ys);
(*/ Define a function repeats of type ''a list -> bool so
that
repeats (L) is true if and only if the list L has two equal
elements next to each other
*)
(*/ Correct, but non-pattern matching version:
fun repeats (L) =
if null L or else null(tl(L))
then false
else if hd(L) = hd(tl(L)) then true
else repeats (tl(L));
*)
fun repeats (nil) = false
| repeats (y::nil) = false
| repeats (y::ys) = if y = hd(ys) then true
else repeats(ys);
Define a function in SML, called "less" of type int * int list -> int list...
in ml language or sml
Exercise 14 Write a function maxpairs of type (int * int) list -> int lise that takes a list of pairs of integers and returns the list of the max elements from each pair. For example, if you evaluate maxpairs ((1,3), (4,2), (-3,-4)] you should get [3,4,-3).
*****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...
In Ocaml Define the function 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;; -...
In SML programming write a function pow of type real * int -> real that raises a real number to an integer power. Your function need not behave well if the integer power is negative.
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]...
Question 1 Assume a function called count_primes is pre-definied. If consumes two int arguments start and stop that returns the number of prime integers between start (inclusive) and stop (exclusive). Note: The start value must be less than or equal to the stop value. Enter 3 assertEqual statements to test the count_primes function. Question 2 Define a function called count_primes that consumes two int arguments start and stop that returns the number of prime integers between start (inclusive) and stop...
Define a function called get_n_largest(numbers, n) which takes a
list of integers and a value n as parameters and returns a
NEW list which contains the n
largest values in the parameter list. The values in the
returned list should be in increasing order. The
returned list must always be of length n. If the number of values
in the original list is less than n, the value
None should be repeated at the end of the returned list to...
Define a function called max_association(), which recieves 2 lists, lst1, which is a list of strings, and lst2, which is a list of integers. The function must return a list of strings associated to the highest integers in lst1. Assume both lists have the same length As an example, the following code fragment: L1 = ['a','b','c','d','e','f','g','h','i','j'] L2 = [1,2,3,1,3,2,3,1,2,1] result = max_association(L1,L2) print(result) should produce the output: ['c', 'e', 'g']
15. Define a class called Point. It has two private data members: x and y with int type; and three public member functions: a constructor, setPoint(int, int) and printPoint0. The constructor initializes the data members to 0. You need to use the operator?: to test whether x and y are positive. If not, assign them to 0. The function printPoint prints the message "(X, Y)" where X and Y are two integers. In the main program, first input the number...
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...