15
1
Given a non-empty set of strings and a list of strings, find out how many times the set occurs in the list, i.e. how many times you could create the set with items from the list. Every element from the list can only be used once.
Hint: a set is an unordered list of unique items.
Default input/output rules apply.
No external libraries allowed. Compiler/Interpreter standard libs are okay. This is code golf, so shortest solution counts.
Test cases:
["apple", "banana"], ["apple", "pear", "apple", "banana", "banana"] => 2
["apple", "banana"], ["apple", "pear", "apple", "banana", "apple"] => 1
["apple", "banana", "pear"], ["apple", "banana", "kiwi", "apple"] => 0
["coconut"], [] => 0
EDIT: removed a sentence stating that the input params are defined in local scope. This contradicts the default IO rules linked above.
Yes that clarifies it. However I am a little hung up on the third sentence. What do you mean by "doesn't handle objects"? – Post Rock Garf Hunter – 2017-04-20T18:45:57.083
@WheatWizard some languages are not object-oriented and don't know the concept of comparing arbitrary objects. – Hubert Grzeskowiak – 2017-04-20T18:47:00.090
1You should probably change that to object-oriented because every language I am aware of does handle objects of some type even if objects are a closed class. I should also point out that there are a good deal of languages that also cannot handle strings at all. – Post Rock Garf Hunter – 2017-04-20T18:49:04.753
@WheatWizard okay, updated description. That paragraph was meant for languages such as C, Assembler or Maple. – Hubert Grzeskowiak – 2017-04-20T18:59:26.463
What languages are object oriented? What should they use if not strings? I think the easiest thing would be to restrict to just strings. Or, alternatively, only integers. See this advice on using the simplest type that suffices.
– xnor – 2017-04-20T19:23:38.750Good point, @xnor. updated. I think the solutions so far are all handling strings just fine, so this won't invalidate any. – Hubert Grzeskowiak – 2017-04-20T19:27:16.127
@AdmBorkBork nope! will add another test for that. – Hubert Grzeskowiak – 2017-04-20T19:42:16.420
The set is non-empty. The list can be empty. – Hubert Grzeskowiak – 2017-04-20T19:45:28.463
OK, I would suggest to explicitly add that. Like "Given a non-empty set of strings and a potentially-empty list of strings" or similar, because as it's currently written my brain reads it as both the set and the list are non-empty. – AdmBorkBork – 2017-04-20T19:47:02.757
For future reference, I'll also direct you to the Sandbox where you can post challenges, get meaningful feedback, and tweak them before they're posted to main.
– AdmBorkBork – 2017-04-20T19:47:59.107@AdmBorkBork thanks. much appreciated. – Hubert Grzeskowiak – 2017-04-20T19:48:37.067
Related: Three fruit pies
– xnor – 2017-04-20T21:50:13.097