Created
February 26, 2013 02:12
-
-
Save adilakhter/5035234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let computeMaxDollars (n:int) (memo:Dictionary<int64,int64>)= | |
let rec computeMaxDollars' (ni:int64) = | |
if ni = 0L || ni = 1L then // base case | |
ni | |
else | |
match memo|> Memo.tryFind ni with | |
| Some (nx) -> nx // found in memo. Returning Result. | |
| None -> | |
let f = computeMaxDollars' | |
let nx = | |
(ni/2L, ni/3L, ni/4L) | |
|> (fun (x,y,z) -> (f x) + (f y) + (f z)) | |
|> (fun nx -> Math.Max(ni,nx)) | |
memo|> Memo.add ni nx |> ignore // storing the result in memo | |
nx | |
computeMaxDollars' (n|>int64) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment