forked from scottbale/vendingmachine-clojure
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d44b82b
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(ns vending-machine.vm) | ||
|
||
(def NICKEL 5) | ||
(def DIME 10) | ||
(def QUARTER 25) | ||
|
||
(defn coin-return [] (list NICKEL DIME)) | ||
|
||
(defn purchase [purchase-price, deposits, coin-return] | ||
"Indicate true/false if purchase succeeded, given the int (cents) purchase | ||
price, sequence of deposited coins, and sequence of available coin return | ||
coins." | ||
|
||
(cond (sufficient-funds purchase-price deposits) | ||
{:success true :change (change-due purchase-price deposits) :reserve deposits} | ||
:else {:success false} | ||
)) | ||
|
||
(defn sufficient-funds [purchase-price, coins] | ||
(<= purchase-price (reduce + coins))) | ||
|
||
(defn change-due [purchase-price, coins] | ||
(- (reduce + coins) purchase-price)) | ||
|
||
(defn make-change [change-due, coins] | ||
0 | ||
) |