Assuming that the algorithm should find the number of occurrences of a string in another string. Which
it shouldn't.
PHP Code:
function findFrequencyOfPattern(haystack, needle)
{
temp.occurrences = 0;
for (temp.i=0; temp.i<haystack.length() - needle.length() + 1; temp.i++) {
if (haystack.substring(temp.i, needle.length()) == needle) temp.occurrences++;
}
return temp.occurrences;
}
PHP Code:
temp.haystack = "AUGCCCGTAUACGTA";
temp.needles = {"CGTA", "CGT", "GTA", "CG", "GT", "TA", "AU", "CC"};
sendrpgmessage(temp.haystack);
for (temp.needle: temp.needles) {
sendrpgmessage(temp.needle @ ": " @ findFrequencyOfPattern(temp.haystack, temp.needle));
}
Outputs:
PHP Code:
AUGCCCGTAUACGTA
CGTA: 2
CGT: 2
GTA: 2
CG: 2
GT: 2
TA: 2
AU: 2
CC: 2