Skip to content

Instantly share code, notes, and snippets.

@benatkin
Created November 26, 2009 07:06
Show Gist options
  • Select an option

  • Save benatkin/243289 to your computer and use it in GitHub Desktop.

Select an option

Save benatkin/243289 to your computer and use it in GitHub Desktop.
require 'diff/lcs'
def wordiff(w1, w2); Diff::LCS.diff(w1.split(//), w2.split(//)); end
def simple_diff(d); d.flatten.map {|c| "#{c.position}#{c.action}#{c.element}"}.join(' '); end
p simple_diff(wordiff('interesting', 'informative'))
# => "2-t 3-e 2+f 3+o 5-e 6-s 5+m 6+a 9-n 10-g 9+v 10+e"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment