Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Differing output for function moved from ruby 1.8 to 1.9

Reply
Thread Tools

Differing output for function moved from ruby 1.8 to 1.9

 
 
DJ Jazzy Linefeed
Guest
Posts: n/a
 
      05-16-2008
Sup, fools?

This is the Levenshtein function I'm gankin' for my file comparison
project (see "40 million comparison..." thread):

# Levenshtein calculator
# Author: Paul Battley ((E-Mail Removed))
# 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.
 
Reply With Quote
 
 
 
 
DJ Jazzy Linefeed
Guest
Posts: n/a
 
      05-16-2008
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).
 
Reply With Quote
 
 
 
 
Phillip Gawlowski
Guest
Posts: n/a
 
      05-16-2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

DJ Jazzy Linefeed 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 Gawlowski
Twitter: twitter.com/cynicalryan
Blog: 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

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

 
Reply With Quote
 
DJ Jazzy Linefeed
Guest
Posts: n/a
 
      05-16-2008
I think a no-brainer prerequisite to this script would be 2.0 actually
being released.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Differing function prototypes and definitions Christopher Key C Programming 3 10-03-2007 12:39 AM
Differing signedness warnings when compiling ruby-odbc. Ben Gribaudo Ruby 0 01-09-2006 03:21 PM
Re: HTML rendering issue: Can someone help me understand why this grid has cells of differing lengths? JV ASP .Net 1 03-24-2005 09:45 PM
documents on differing paradigms Jo Blow ASP .Net 0 12-25-2004 11:11 PM
[ANN] ruby-freedb, ruby-serialport, ruby-mp3info moved to Rubyforge guillaume.pierronnet@ratp.fr Ruby 0 08-31-2003 11:57 PM



Advertisments