Created
November 6, 2013 14:14
-
-
Save dtinth/7336694 to your computer and use it in GitHub Desktop.
Single Statement Pam Kuan Solution (Ruby)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gets.to_i.times { puts gets.strip | |
.gsub(/^([^aeiou]*)([aeiou]\w*)( [^aeiou]*)([aeiou]\w*)$/, '\\1\\4\\3\\2') | |
.gsub(/^([^aeiou]*)([aeiou]\w*)( \w+ [^aeiou]*)([aeiou]\w*)$/, '\\1\\4\\3\\2') | |
.gsub(/^(\w+ [^aeiou]*)([aeiou]\w*)( \w+ [^aeiou]*)([aeiou]\w*)$/, '\\1\\4\\3\\2') | |
.gsub(/^(\w+ [^aeiou]*)([aeiou]\w*)( \w+ \w+ [^aeiou]*)([aeiou]\w*)$/, '\\1\\4\\3\\2') | |
.gsub(/^(\w+ \w+ [^aeiou]*)([aeiou]\w*)( \w+ \w+ [^aeiou]*)([aeiou]\w*)$/, '\\1\\4\\3\\2') | |
.gsub(/^(\w+ \w+ [^aeiou]*)([aeiou]\w*)( \w+ \w+ \w+ [^aeiou]*)([aeiou]\w*)$/, '\\1\\4\\3\\2') } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can be collapse this
into
or, more readable w/o nested group
and so on.
finally, with the help of lambda, we could do something like meta-regex, such as