From: Chris Hulan Date: 2010-09-29T03:10:12+09:00 Subject: Re: levenshtein function issue On Sep 27, 3:37 pm, Joe Smith wrote: > Chris Hulan wrote: > > On Sep 26, 12:43 am, Joe Smith wrote: > >> error... (that's why I had originally changed it) > >> -- > >> Posted viahttp://www.ruby-forum.com/. > > > Looking at the description athttp://www.levenshtein.net/it appears > > that both m and n should be +1 > > The strings are then offset to allow indexing from 1.  Guess you > > either need to add a character (blank?) > > to the beginning of both strings, or adjust your indexes into s and t > > (the 1st char is the 0th index) > > > I'm totally pulling this out of my head, as I don't have Ruby on my > > work computer > > Thank you for the reply.  Unfortunately, I get the same error when I try > this :( > -- > Posted viahttp://www.ruby-forum.com/. This was bugging me so I installed Ruby and gave it a go. You do need to change that 'n-1' to be 'n+1' Then in the nested loop you need to use both indexes: for j in 1..n for i in 1..m if(s[i].eql?(t[i])) then ^this 'i' should be 'j' But you still need to adjust the indexes into the strings (i-1 and j-1 seems to work here) cheers