View Single Post
  #4  
Old 03-26-2008, 05:05 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Okay, I have mine finished. It takes about 5 seconds to run (go figure!) but it gets the right answer, at least from what I have seen.

PHP Code:
String: AU, Occurances: 2
String
: CC, Occurances: 2
String
: CG, Occurances: 2
String
: CGT, Occurances: 2
String
: CGTA, Occurances: 2
String
: GT, Occurances: 2
String
: GTA, Occurances: 2
String
: TA, Occurances: 2 
This is what it outputs in RC.

The script is very inefficient and slow, but it works ...

NOTE: You will need to change the [] in the format to a percent sign, it won't let me post without giving me a bad request error. Look for this line:
echo( format( "String: []s, Occurances: []s", rc[0], rc[1] ) );

PHP Code:
function onCreated()
{
  
temp.includeSingle = false; // Include ones that only appear once?
  
  
temp.n = "AUGCCCGTAUACGTA";
  
temp.na = stringToArrayList( n );
    
  
temp.occ = {};
  
  for ( 
temp.r : na )
  {
    
temp.fr = findFrequency( n, r );
    if ( 
temp.fr == 1 && includeSingle == false )
    {
      continue;
    }
    
occ.add( { r, temp.fr } );
  }
  
  for ( 
temp.rc : occ )
  {
    echo( 
format( "String: []s, Occurances: []s", rc[0], rc[1] ) );
  }
}
function 
stringToArrayList( str )
{
  
temp.p = {};
  for ( 
temp.char = 0; char < str.length(); char ++ )
  {
    for ( 
temp.charlen = 2; charlen < str.length() +  1 - char; charlen ++ )
    {
      
temp.count ++;
      
temp.newText = str.substring( char, charlen );
      if ( 
newText != str && p.index( @ newText ) == -1 )
      {
        
p.add( newText );
      }
      if ( 
count >= 100 )
      {
        
sleep( .05 );
        
count = 0;
      }
    }
  }
  return 
p;
}
function 
findFrequency( str, phrase )
{
  
temp.o = 0;
  for ( 
temp.char = 0; char < str.length(); char ++ )
  {
    for ( 
temp.charlen = 1; charlen < str.length() +  1 - char; charlen ++ )
    {
      
temp.count ++;
      
temp.newText = str.substring( char, charlen );
      if ( 
newText != str )
      {
        if ( 
newText == phrase )
        {
          
o ++;
        }
      }
      if ( 
count >= 100 )
      {
        
sleep( .05 );
        
count = 0;
      }
    }
  }
  return 
o;
} 
This looks for all possible combinations, then finds how often they occur.

Also, if a mod wants to delete my last post in this thread they can, it won't let me edit it or delete it anymore for some reason, gives a Bad Request error.
__________________
Reply With Quote