I am trying to create a sequence lazily using F #.
The sequence is defined as follows:
the nth term of the sequence of the number of triangles is given by the expression tn = Β½n (n + 1); so the first decimal of the number:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
Here is what I still have, but it doesn't seem to work:
let tri_seq = 1.0 |> Seq.unfold (fun x -> match x with | _ -> Some (x, 0.5*x*(x + 1.0)))
Thank you very much who can help me figure out how the work unfolds. Thanks
Edit: I correctly defined the first answer, but dosnt works, however, I changed it a bit and it worked.
let tri_seq = 1.0 |> Seq.unfold (fun x -> Some (0.5 * x * (x + 1.0),x + 1.0))
source share