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
(defn profits | |
"Takes a sequence of prices representing prices on consecutive days and returns a sequence of tuples containing | |
possible profitable transactions resulting from buying and selling on those days. The first member of the tuple | |
is a vector containing the 0 based day of purchase and sale. The second member is the profit from the transaction. | |
E.g. an input of [1 7 1 5 4 20] will return | |
([[0 1] 6] [[0 3] 4] [[0 4] 3] [[0 5] 19] [[1 5] 13] [[2 3] 4] [[2 4] 3] [[2 5] 19] [[3 5] 15] [[4 5] 16])" | |
[prices] | |
(apply | |
concat | |
(keep-indexed |