Sign In
Password Recovery Register

Longest Common Substring

No description :/

LenLongStr <- function(String1, String2) {

  s1 <- unlist(strsplit(String1,split="")) # rozbicie stringu na tablice znakow
  s2 <- unlist(strsplit(String2,split=""))

  num <- matrix(0,nchar(String1),nchar(String2) )		
  maxlen <- 0

  for (i in 1:nchar(String1)) {
	
	for (j in 1:nchar(String2)) {
		
		if (s1[i] == s2[j]) {
			if ((i==1) || (j==1)) { 
				num[i,j] <- 1
			} 
			else {
				num[i,j] <- 1+num[i-1,j-1]
			}
		    if (num[i,j] > maxlen) {
				maxlen <- num[i,j]
			}
 		}
	}
  }

  maxlen			
}

Comments

Login or Register to comment.


Embed Me!

Feel free to adjust iframe width and height according to your needs.

<iframe width="800px" 
        src="http://www.emoticode.net/embed/r/longest-common-substring.html" 
        height="400px" 
        frameborder="0"> 
</iframe>

Here's how it will look like.