Skip to content

Instantly share code, notes, and snippets.

@Edmundworks
Created June 27, 2018 10:04
Show Gist options
  • Save Edmundworks/56163230d554696015725fc8d655fc9a to your computer and use it in GitHub Desktop.
Save Edmundworks/56163230d554696015725fc8d655fc9a to your computer and use it in GitHub Desktop.
coin 2
cases when the amount cannot be made up:
amount < min-denomination
smallest-remainder-of-amount / min-denom is not an integer
actually the above isn't right - if the coins were say 71, 4 and 3 and the amount was 75
Actually in that case smallest-remainder-of-amount would be 0
0/x is still 0
is 0 an integer?
https://www.google.co.uk/search?q=is+zero+an+integer&rlz=1C1CHBF_en-GBGB741GB742&oq=is+zero+an+in&aqs=chrome.2.69i57j6j0l4.3728j1j7&sourceid=chrome&ie=UTF-8
https://www.quora.com/Is-0-an-integer
it would appear so
so in order to work out the cases where we return -1 we need to:
a) calculate smallest-remainder-of-amount
b) have an "integer checker"
we can then use this to calculate our answer as well because "smallest-remainder of amount" is 0 we have counted through amount
would also need a "counter" keeping track of how many of each coin we have used to get down from amount to 0
our denominations range from denom-1 to denom-max each of which have an actual numerical value
we want to take amount, subtract denom-max until the remainder is smaller than 1 * denom-max, then apply the same process with denom-(max - 1)
until we have an amount that is 0
if we arrive at an amount smaller than the current deonomination AND smaller than the minimum denomination we stop and return -1
define coin-iter a denom-x
(- amount (* a denom-x)
denom-x)))
if ( < (coin-iter a denom-x) denom-x)
and (> (coin-iter a denom-x) 0))
then (coin-iter a denom-(- x 1)
else (coin-iter (- a 1) denom-x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment