Skip to content

Instantly share code, notes, and snippets.

@follesoe
Created December 2, 2015 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save follesoe/8ca0cfba7e6be23b029f to your computer and use it in GitHub Desktop.
Save follesoe/8ca0cfba7e6be23b029f to your computer and use it in GitHub Desktop.
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