Skip to content

Instantly share code, notes, and snippets.

@chase-lambert
Last active November 19, 2024 05:16
Show Gist options
  • Save chase-lambert/06a2961201129448dc60e81f8660153b to your computer and use it in GitHub Desktop.
Save chase-lambert/06a2961201129448dc60e81f8660153b to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 24.11.17
(ns max-the-stock
(:require [clojure.test :refer [deftest is]]))
(defn max-the-stock [prices]
(->> (rest prices)
(reduce (fn [[min-price max-profit] price]
[(min min-price price)
(max max-profit (- price min-price))])
[(first prices) 0])
second))
(deftest max-the-stock-test
(is (= (max-the-stock [7 1 5 3 6 4])
5))
(is (= (max-the-stock [7 6 4 3 1])
0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment