Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.46 KB | None | 0 0
  1. let findBest best lowest next =
  2.     let bestProfitCandidate = next - lowest
  3.     if bestProfitCandidate > best then bestProfitCandidate else best
  4.  
  5. let maxProfit lst =
  6.     let rec calcMaxProfit lowest best rem =
  7.         match rem with
  8.         | [] -> best
  9.         | x::xs -> let lowest' = if x < lowest then x else lowest
  10.                   calcMaxProfit lowest' (findBest best lowest x) xs
  11.     let startLow = List.nth lst 0
  12.     calcMaxProfit startLow 0 lst
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement