Question: Please solve these two USING F# (i) Write directly by recursion a function findSum : int -> int list -> int that takes a tar-

Please solve these two USING F#

Please solve these two USING F# (i) Write directly by recursion a

(i) Write directly by recursion a function findSum : int -> int list -> int that takes a tar- get sum and a list xs, and returns the smallest n such that the sum of the first n elements of the list is the target sum. Your function should return the length if there is no such n. > findSumo [] ;; val it : int = 0 > findSum 2 (1;-1;3;-1] ;; val it : int = 4 > findSum 2 [1;-1;3;-1;1;5] ; ; val it : int = 4 > findSum 5 [1;5; -2;3; -7]; ; val it : int = 5 (ii) Reimplement findSum using fold, by filling in the ... in the following declaration: let findSum2 sum xs = let (, n) = List.fold (fun (r, i) -> fun x -> ...) (sum, 0) xs (i) Write directly by recursion a function findSum : int -> int list -> int that takes a tar- get sum and a list xs, and returns the smallest n such that the sum of the first n elements of the list is the target sum. Your function should return the length if there is no such n. > findSumo [] ;; val it : int = 0 > findSum 2 (1;-1;3;-1] ;; val it : int = 4 > findSum 2 [1;-1;3;-1;1;5] ; ; val it : int = 4 > findSum 5 [1;5; -2;3; -7]; ; val it : int = 5 (ii) Reimplement findSum using fold, by filling in the ... in the following declaration: let findSum2 sum xs = let (, n) = List.fold (fun (r, i) -> fun x -> ...) (sum, 0) xs

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!