Last active
July 28, 2023 17:29
-
-
Save chase-lambert/7f3c7f78c644ffde8b21a6d27be44d37 to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 23-07-23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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