View Single Post
  #3  
Old 03-26-2008, 03:25 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Assuming that the algorithm should find the number of occurrences of a string in another string. Which it shouldn't.

PHP Code:
function findFrequencyOfPattern(haystackneedle)
{
  
temp.occurrences 0;
  for (
temp.i=0temp.i<haystack.length() - needle.length() + 1temp.i++) {
    if (
haystack.substring(temp.ineedle.length()) == needletemp.occurrences++;
  }
  return 
temp.occurrences;

PHP Code:
temp.haystack "AUGCCCGTAUACGTA";
temp.needles = {"CGTA""CGT""GTA""CG""GT""TA""AU""CC"};
sendrpgmessage(temp.haystack);
for (
temp.needletemp.needles) {
  
sendrpgmessage(temp.needle ": " findFrequencyOfPattern(temp.haystacktemp.needle));

Outputs:
PHP Code:
AUGCCCGTAUACGTA
CGTA
2
CGT
2
GTA
2
CG
2
GT
2
TA
2
AU
2
CC


Last edited by DrakilorP2P; 03-26-2008 at 09:57 AM..
Reply With Quote