Skip to content

Instantly share code, notes, and snippets.

@chase-lambert
Last active July 28, 2023 17:29
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 chase-lambert/7f3c7f78c644ffde8b21a6d27be44d37 to your computer and use it in GitHub Desktop.
Save chase-lambert/7f3c7f78c644ffde8b21a6d27be44d37 to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 23-07-23
(ns maximum-profit
(:require [clojure.test :refer [deftest is]))
(defn maximum-profit [prices]
(loop [n (first prices)
xs (rest prices)
acc []]
(if (seq xs)
(let [max-profit (apply max
(map #(- % n) xs))]
(recur (first xs) (rest xs) (conj acc max-profit)))
(max 0 (apply max acc)))))
(deftest maximum-profit-test
(is (= 5 (maximum-profit [7 1 5 3 6 4]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment