3 ms·
I can't really understand your version, I'm not familiar with scala. Is this somewhat equivalent? I tried to use Clojure's loop/recur but I'm too much of a noob
by NoodleIncident 13y ago
I can't really understand your version, I'm not familiar with scala. Is this somewhat equivalent? I tried to use Clojure's loop/recur but I'm too much of a noob. :(
def max_profit(stocks):
def r(stocks, profit, lowest):
return r(stocks[1:],
max([profit, stocks[0] - lowest]),
min([lowest, stocks[0]]))
return r(stocks[1:], 0, stocks[0])
- dxbydt 13y agoI think so. You've basically reimplemented a fold, but clojure stdlib has a built-in left fold. See line 84 https://github.com/clojure/clojure/blob/master/src/clj/clojure/core/reducers.clj https://github.com/clojure/clojure/blob/master/src/clj/cloju...