Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.net
- // See the 'F# Tutorial' project for more help.
- open System.Collections.Generic
- let inline left (x, y) = (x + 1, y)
- let inline down (x, y) = (x, y + 1)
- let max = 30
- let (|Left|Down|Both|End|) (x, y) =
- if (x < max && y >= max) then Left
- else if (x >= max && y < max) then Down
- else if (x < max && y < max) then Both
- else End
- let cache = Dictionary<_,_>()
- let addToCache x res =
- cache.Add(x,res)
- res
- let rec compute2 x =
- match cache.TryGetValue(x) with
- | true,r -> r
- | _ ->
- match x with
- | End -> 1L
- | Left -> compute2 (left x) |> addToCache x
- | Down -> compute2 (down x) |> addToCache x
- | Both -> compute2 (left x) + compute2 (down x) |> addToCache x
- [<EntryPoint>]
- let main argv =
- // let processing = compute (1, 1) 0L (fun x -> x)
- //printfn "%A" processing
- let processing = compute2 (1, 1)
- printfn "%A" processing
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement