View Single Post
  #51  
Old 04-22-2008, 10:04 PM
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
Quote:
Originally Posted by Tolnaftate2004 View Post
Okay, well this thread has been dead for sufficiently long time. Here is what I came up with; it takes quadratic time.

PHP Code:
function onCreated() {
  
temp.getpatterns("THISISATESTSTRING");
  for (
temp.stemp.p) {
    if (
this.(@"h_"@temp.s) >= 2)
      echo(
temp.": "this.(@"h_"@temp.s));
    
this.(@"h_"@temp.s) = 0/* clean-up */
  
}
}

function 
getpatterns(s) {
  
temp.s.length();
  
temp.pat.clear();
  for (
temp.i=0temp.i<temp.l-1temp.i++) {
    
temp.s.charat(temp.i);
    for (
temp.j=temp.i+1;temp.j<temp.l;temp.j++) {
      
temp.@= s.charat(temp.j);
      
this.(@"h_"@temp.c) ++;
      
temp.pat.add(temp.c);
    }
  }
  return 
temp.pat;

Perhaps there are still improvements to be made.
There are always improvements to be made, unless Stefan makes it, in which case it must be perfect.
__________________
Reply With Quote