Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Fibonacci Number formula
- let rec fib n =
- match n with
- | 0 | 1 -> n
- | _ -> fib (n - 1) + fib (n - 2)
- /// Another approach - a lazy infinite sequence of Fibonacci numbers
- let fibSeq = Seq.unfold (fun (a,b) -> Some(a+b, (b, a+b))) (0,1)
- // Print even fibs
- [1 .. 10]
- |> List.map fib
- |> List.filter (fun n -> (n % 2) = 0)
- |> printList
- // Same thing, using a list expression
- [ for i in 1..10 do
- let r = fib i
- if r % 2 = 0 then yield r ]
- |> printList
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement