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#

(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
Get step-by-step solutions from verified subject matter experts
