For me, of all the threads in the forum, the 'Challenge' threads are my favourite since they usually produce very interesting and imaginative code. However, I haven't seen or participated in such a thread in quite a while, so thought it was time to post one.
With a plethora of past challenges, it becomes difficult to find a topic that hasn't already been explored. This time, I pose a challenge with a possible practical application: a function to calculate the amount of each
denomination of some arbitrary currency for a given amount.
Example: In the UK, for amounts less than £1, we have 50p, 20p, 10p, 5p, 2p, and 1p denominations.
So, given an amount of 67p = 50p + 10p + 5p + 2p
So, the challenge would be to write a function requiring two parameters: a numerical amount for which to calculate the change, and a list of denominations.
The function would then return a list of dotted pairs, giving the minimum number of 'coins' to make up the amount, e.g.:
_$ (_givechange 67 '(50 20 10 5 2 1))
==> ((50 . 1) (10 . 1) (5 . 1) (2 . 1))
The list of denominations could of course be arbitrary to suit any currency (as long as the list contained a unit element).
I hope others enjoy participating in the challenge as much as I have.
Enjoy!
Lee