29
1
Write a program which calculates if an inputted monetary value, as an integer, can be represented by a unique combination of coins and/or notes, that meaning the same coin/note cannot be used more than once.
Your program should take a value as input, and can take a list of coin/note values either via input or via your language's equivalent of an array. The list of coins/notes should be able to change, so make sure it's clear where this is defined if you're using a constant.
Your program should output any truthy/falsy value respectively.
Please note that outputting the list of coins/notes that make up the value is not required.
EXAMPLE
Using the UK pound, (£1.00 = 100 and £420.69 = 42069)
coins = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000]
The following will output true:
6 (1, 5)
15 (10, 5)
88 (1, 2, 5, 10, 20, 50)
512 (500, 10, 2)
7003 (5000, 2000, 2, 1)
The following will output false:
4
209
8889
4242424242
[ANYTHING ABOVE 8888]
ALTERNATIVE TEST DATA (US Dollar)
coins = [1, 5, 10, 25, 50, 100, 200, 500, 1000, 2000, 5000, 10000]
Good luck!
4I wish we have more newcomers like you... – Leaky Nun – 2017-05-08T17:41:10.637
Related – Adnan – 2017-05-08T17:55:12.903
2You should add some testcases using a different set of coin – Leaky Nun – 2017-05-08T18:18:12.813
Can we assume the input coin values are sorted? – Digital Trauma – 2017-05-08T19:37:49.380
@DigitalTrauma I'm afraid not – Eddie Hart – 2017-05-08T19:38:53.517
2I'd suggest adding test cases that cannot be solved with the greedy heuristic of taking the largest unused coin that is that is at most the remaining value. It would also be good to have ones where the input isn't sorted and where a value can be made more than one way. It's generally good for test cases to avoid the possibility that someone makes a reasonable attempt at the problem that works for the test cases without being right on everything. – xnor – 2017-05-08T20:17:45.787
2Related. Also related. The former question is arguably a duplicate, but this question is IMO better-designed and if we're to close one as a duplicate, I'd rather close the older one. – None – 2017-05-08T21:24:12.403
Very closely related – Post Rock Garf Hunter – 2017-05-08T21:49:46.603
Kind of related but the overall endpoint of the challenge is very different – Beta Decay – 2017-05-08T22:03:26.927
@xnor I agree, but I think for most currencies (particularly a 1/2/5 set) there aren't any combinations that return truthy that are also unsolvable by the greedy heuristic. We'd need a different set of coins (the McDonald's chicken nugget boxes?) – Draco18s no longer trusts SE – 2017-05-08T22:06:22.293
Wow there are a lot of near-duplicates of this question. In some languages, the best answer to that question would also be the best answer to this one. In other languages, the two would differ. – None – 2017-05-09T06:51:30.357
Yet another related question, this time as a more general variant. – Peter Taylor – 2017-05-09T08:10:38.783