Created
December 2, 2015 08:48
-
-
Save follesoe/8ca0cfba7e6be23b029f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
open System.IO | |
let prices = File.ReadLines(__SOURCE_DIRECTORY__ + "/2/input.txt") | |
|> Seq.map System.Double.Parse | |
|> Seq.toList | |
let rec findMax price prices profit = | |
match prices with | |
| [] -> profit | |
| hd :: tail -> | |
if hd - price > profit then findMax price tail (hd - price) | |
else findMax price tail profit | |
let rec solve prices profit = | |
match prices with | |
| [] -> profit | |
| hd :: tail -> | |
let candidate = findMax hd tail profit | |
if candidate > profit then solve tail candidate | |
else solve tail profit | |
printfn "Max profit: %.4f" (solve prices 0.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment