Skip to content

Instantly share code, notes, and snippets.

@reinh
Created July 8, 2010 21:34
Show Gist options
  • Save reinh/468680 to your computer and use it in GitHub Desktop.
Save reinh/468680 to your computer and use it in GitHub Desktop.
def substr(str1, str2)
len = str1.length
last = (0...len).detect{|i| str1[i] != str2[i]}
last ||= len
str1[0...last]
end
def gcp(strings)
sorted = strings.sort
substr(sorted.first, sorted.last)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment