I have attempted to make a recursive function that utilizes match to create a Fibonacci sequence. I got Euler2 to work, but in Euler2a I'm trying to have the entire function self-contained except for the iteration constraint, j.
How must Euler2a change in order for it to provide the sequence?
Any pointers are most appreciated. :)
The results from Euler2
val Euler2 : list:int list -> i:int -> j:int -> int list
val z : int list = [1; 2; 3; 5; 8; 13; 21; 34; 55; 89]
The results from Euler2a
val Euler2a : j:int -> (int list -> int -> int -> int list)
val z2 : (int list -> int -> int -> int list)
Euler2
let rec Euler2 (list: int list) i j =
match i with
| 1 | 2 -> Euler2 list (i+1) j
| _ when (i<=j) -> let newList = list @ [list.[list.Length - 1] + list.[list.Length - 2]]
Euler2 newList (i+1) j
| _ -> list
let z = Euler2 [1;2] 1 10
Euler2
let rec Euler2a (j:int) =
let i = 1
let list = [1;2]
let rec Euler2b (list: int list) i j =
match i with
| 1 | 2 -> Euler2b list (i+1) j
| _ when (i<=j) -> let newList = list @ [list.[list.Length - 1] + list.[list.Length - 2]]
Euler2b newList (i+1) j
| _ -> list
Euler2b
let z2 = Euler2a 10