Generating Fibonacci series in F#

后端 未结 11 1913
南方客
南方客 2020-12-31 02:58

I\'m just starting to learn F# using VS2010 and below is my first attempt at generating the Fibonacci series. What I\'m trying to do is to build a list of all numbers less

11条回答
  •  被撕碎了的回忆
    2020-12-31 03:34

    One using aggregation (fold):

    let fib n = 
      [1..n] |> List.fold (fun ac _ -> (ac |> List.take 2 |> List.sum) :: ac) [1;1] |> List.rev
    

提交回复
热议问题