# Differing output for function moved from ruby 1.8 to 1.9

**URL:** <https://www.ruby-forum.com/t/differing-output-for-function-moved-from-ruby-1-8-to-1-9/137766>\
**Category:** Ruby\
**Created:** [May 16, 2008, 3:55am UTC](https://www.ruby-forum.com/t/differing-output-for-function-moved-from-ruby-1-8-to-1-9/137766 "2008-05-16T03:55:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DJ\_Jazzy\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f05b48/32.png) [@DJ\_Jazzy\_L](https://www.ruby-forum.com/u/DJ_Jazzy_L)\
**Post date:** [May 16, 2008, 3:55am UTC](https://www.ruby-forum.com/t/differing-output-for-function-moved-from-ruby-1-8-to-1-9/137766/1 "2008-05-16T03:55:36Z")

</div>

Sup, fools?

This is the Levenshtein function I’m gankin’ for my file comparison  
project (see “40 million comparison…” thread):

# Levenshtein calculator

# Author: Paul B. (removed\_email\_address@domain.invalid)

# Modified slightly by John Perkins:

# – removed $KCODE call

def distance(str1, str2)

unpack\_rule = ‘C\*’  
s = str1.unpack(unpack\_rule)  
t = str2.unpack(unpack\_rule)  
n = s.length  
m = t.length

return m if (0 == n) # stop the madness if either string is empty  
return n if (0 == m)

d = (0…m).to\_a  
x = nil

(0…n).each do |i|  
e = i + 1  
(0…m).each do |j|  
cost = (s[i] == t[j]) ? 0 : 1  
x = [  
d[j + 1] + 1, # insertion  
e + 1, # deletion  
d[j] + cost # substitution  
].min  
d[j] = e  
e = x  
end  
d[m] = x  
end

return x  
end

When I ran this with test data in ruby 1.8 the output was 969, but  
when I ran it on a 1.9 install the output was 1011. I’m aware that  
some of the rules have changed, especially with arrays. Does anyone  
see where the discrepancy lies, because I sure as heck don’t. The  
files didn’t change so the distance shouldn’t either. Thanks for all  
your help in advance.

---

<div class="post-metadata">

**Author:** ![DJ\_Jazzy\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f05b48/32.png) [@DJ\_Jazzy\_L](https://www.ruby-forum.com/u/DJ_Jazzy_L)\
**Post date:** [May 16, 2008, 5:00am UTC](https://www.ruby-forum.com/t/differing-output-for-function-moved-from-ruby-1-8-to-1-9/137766/2 "2008-05-16T05:00:47Z")

</div>

Here’s an idea: a migration script that detects when and where a  
script will break after the big 1.9/2 move.

I’m not that good of a rubyist, but I know there’s about a dozen  
people reading these that could have it done by Friday night (I’m  
looking at YOU, \_why).

---

<div class="post-metadata">

**Author:** ![DJ\_Jazzy\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f05b48/32.png) [@DJ\_Jazzy\_L](https://www.ruby-forum.com/u/DJ_Jazzy_L)\
**Post date:** [May 16, 2008, 5:27am UTC](https://www.ruby-forum.com/t/differing-output-for-function-moved-from-ruby-1-8-to-1-9/137766/3 "2008-05-16T05:27:41Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

DJ Jazzy L. wrote:  
| Here’s an idea: a migration script that detects when and where a  
| script will break after the big 1.9/2 move.  
|  
| I’m not that good of a rubyist, but I know there’s about a dozen  
| people reading these that could have it done by Friday night (I’m  
| looking at YOU, \_why).

Maybe _the_ chance to get your 15 minutes of fame, and deepen your  
understanding of Ruby at the same time.

* * *

Phillip G.  
Twitter: [twitter.com/cynicalryan](http://twitter.com/cynicalryan)  
Blog: [http://justarubyist.blogspot.com](http://justarubyist.blogspot.com)

Use recursive procedures for recursively-defined data structures.  
~ - The Elements of Programming Style (Kernighan & Plaugher)  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkgs/uMACgkQbtAgaoJTgL9c6gCdHNEyySRQx9kSdoAiO1gcy3T3  
WYQAnR3pbFzYV+ruMrxv2h8mag3J9OqX  
=+ICc  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![DJ\_Jazzy\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f05b48/32.png) [@DJ\_Jazzy\_L](https://www.ruby-forum.com/u/DJ_Jazzy_L)\
**Post date:** [May 16, 2008, 6:05am UTC](https://www.ruby-forum.com/t/differing-output-for-function-moved-from-ruby-1-8-to-1-9/137766/4 "2008-05-16T06:05:41Z")

</div>

I think a no-brainer prerequisite to this script would be 2.0 actually  
being released.
