# Problem 4 Write maxrun , a function which returns the length of the longest sublist of negative or non-negative numbers and a list of absolute values of the original list elements. Ensure that this...

7

Ocaml Question

Extracted text: Problem 4 Write maxrun , a function which returns the length of the longest sublist of negative or non-negative numbers and a list of absolute values of the original list elements. Ensure that this list is in the same order. To report multiple outputs, use a record. We'll define this particular output record as run_output : type run_output = { length : int; entries : int list; } Template: let maxrun (l:int list) : run_output = (** YOUR CODE HERE **) Sample Unit Test let out = moveNeg [8; -5; 3; 0; 10; -4] in if out.length = 3 && out.entries = [8; 5; 3; 0; 10; 4] then print_string "YAY" else raise (Failure "00PS");

Answered 122 days AfterJun 04, 2022

## Answer To: Problem 4 Write maxrun , a function which returns the length of the longest sublist of negative or...

Ajay answered on Oct 04 2022
Codes
run_output = {
l = maxrun,
list = abs_list
}
function maxrun(list)
max = -1

count = 1
current = list[1]
for i = 2,#list do
element = list[i]
if element >= 0 and current >= 0 then
count = count + 1
elseif element < 0 and current < 0 then
count = count + 1
else
count = 1
end
if count > max then
max = count
end
current = element
end
return {
l = max,
list = list
}
end
function abs(list)
for i = 1,#list do
list[i] = math.abs(list[i])
end
return list
end
abs_list = abs([-6, 2, -3, -4, 9, -8,...
SOLUTION.PDF

### Submit New Assignment

Copy and Paste Your Assignment Here