9
Given two strings, a parent string and a query string respectively, your task is to determine how many times the query string, or an anagram of the query string; appears in the parent string, in a case-sensitive search.
Examples of Behaviour
Input 1
AdnBndAndBdaBn
dAn
Output 1
4
Explanation The substrings are highlighted in bold below:
AdnBndAndBdaBn
AdnBndAndBdaBn
AdnBndAndBdaBn
AdnBndAndBdaBn
Note the search MUST be case sensitive for all searches.
Input 2
AbrAcadAbRa
cAda
Output 2
2
This must work for standard ASCII only. This is code-golf, so shortest number of characters will get the tick of approval. Also please post a non-golfed version of your code along with the golfed version.
2Important test case:
abacacaba
aac
– Martin Ender – 2015-05-15T21:24:03.243Will the parent string always be longer than the query string ? – Optimizer – 2015-05-15T22:52:19.673
Oh very good point! Yes @Optimizer, the parent string will always be longer than the query string. – WallyWest – 2015-05-16T00:52:58.250
@WallyWest What about the additional test case? Should overlapping occurrences of a single permutation be counted? – Martin Ender – 2015-05-16T03:15:24.920
1Can you give a test case and its correct solution for your most recent comment? – isaacg – 2015-05-16T08:58:16.380
Can the input be on one line, space seperated? – Tim – 2015-05-16T09:51:24.477
@WallyWest, your most recent comment contradicts the question and, as far as I can tell, all seven undeleted answers. I think the only sensible option you have is to delete the comment and to edit the question to be explicit that the substrings may overlap. – Peter Taylor – 2015-05-16T12:20:06.633
@PeterTaylor A valid point... granted, a substring may overlap... – WallyWest – 2015-05-16T18:07:11.257