Euler in f#
Here is my solution to Euler problem 2 in F#
I took the memoization code from Wiki Books
Yeah I know I should use infinite lists - but have not come around to it yet
let memoize f =
let dict = new System.Collections.Generic.Dictionary<_,_>()
fun n ->
match dict.TryGetValue(n) with
| (true, v) -> v
| _ ->
let temp = f(n)
dict.Add(n, temp)
temp
let rec fib = memoize(fun n ->
match n with
| 1 | 2 -> 1
| _ -> fib (n-2) + fib(n-1))
let evenNumbers x = x % 2 = 0
let belowBelow4millions x = x < 4000000
[1..50] |> List.map fib |> List.filter belowBelow4millions |> List.filter evenNumbers |> List.sum |> Dump