Skip to content

Instantly share code, notes, and snippets.

@hugopeixoto
Created July 30, 2011 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugopeixoto/1115787 to your computer and use it in GitHub Desktop.
Save hugopeixoto/1115787 to your computer and use it in GitHub Desktop.
Regex problem
"EEB".gsub(/(\w)\1/,'\1X\1') # "EXEB"
"EEEB".gsub(/(\w)\1\1/,'\1X\1Z\1') # "EXEZEB"
"EEEEB".gsub(/(\w)\1\1\1/,'\1X\1Z\1X\1') # "EXEZEXEB"
def mutate (str)
def derp (str, b, c)
return "" if str.nil?
return str if str[0] != b[0]
return c[0] + str[0] + derp(str[1..-1], b, c[1] + c[0])
end
return str[0] + derp(str[1..-1], str[0], "XZ")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment