Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help to solve this problem in Ocaml Define the function everyNth : ('a list) -> int -> ('a list) that will take a

I need help to solve this problem 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;; - : int list = [3; 6] # everyNth [1;2;3;4;5;6] 7;; - : int list = [] # 

Use the function everyNth to define the function everyThird that takes the third element of each given list. Note that your solution must use everyNth, i.e. it is not okay to define everyThird from first principles. In case there is any doubt, the behavior expected from the function is of the following kind:

# everyThird [1; 2; 3; 4; 5];; - : int list = [3] # everyThird [1; 2; 3; 4; 5; 6];; - : int list = [3; 6] # everyThird [];; - : 'a list = [] # 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions