I heva this wierd text where vewols seem to be ratetod :

I'm a badly written text. Some lunatic guy played with the order of vowels. Please fix me !

So I'd need a pragrom which can rateto the vewols (and the 'y' letter as it seems) back so that the text is raadeble agian.

Ouy can choeso the lungaega of ouyr chieco privedod ouy meka a cempleto pragrom (so not just a finctoun). The yntre can be an unpit feild, a text feli, or the cammond leni. The uutpot mya olsa vyra as ouy leki.

Of cuerso I'll anvilid yna pragrom uutpitong bad texts. There's no vulea in a pragrom which mekas texts ouy can't endarstund. But ouy can wreti ouyr cemmonts and qeistouns in ratetod texts if ouy want.


  • Your program is only required to handle ASCII text.
  • For the purposes of this question, the following characters are vowels: aeiouy
  • The positions of the vowels within each word should be rotated. There is some flexibility in deciding what qualifies as a word: the minimum requirement is that two characters separated by a space are in different words, and that two alphabetic characters (a-zA-Z) separated only by alphabetic characters are in the same word.
  • The desired direction of rotation should be inferred from the test cases below.

Test cases

Input: I'm a badly written text. Some lunatic guy played with the order of vowels. Please fix me !
Output: I'm a bydla wrettin text. Semo lanituc gyu plyead with the erdor of vewols. Plaese fix me !

Input: AeiOuy
Output: EioUya

Input: Hyphenated-word
Output: Hephanetyd-word or Hephanetod-wyrd

  • 1
    \$\begingroup\$ Define vowel. \$\endgroup\$ Jun 6, 2013 at 14:04
  • 5
    \$\begingroup\$ I leki "preserve" in this centoxt. \$\endgroup\$
    – Howard
    Jun 6, 2013 at 14:22
  • 2
    \$\begingroup\$ The question is deliberately opaque. Given that there are several possible definitions (among others, only the 10 code-points corresponding to aeiouAEIOU in ASCII / Basic Latin; those code-points plus any others in Basic Latin and Latin-1 Supplement which have those basic characters combined with a diacritic), the question should be explicit. \$\endgroup\$ Jun 6, 2013 at 14:30
  • 1
    \$\begingroup\$ @PeterTaylor I assume ASCII \$\endgroup\$ Jun 6, 2013 at 14:31
  • 8
    \$\begingroup\$ The game should not be about guessing the problem. See the FAQ: "All questions on this site, whether a programming puzzle or a code golf, should have … A clear specification of what constitutes a correct submission." \$\endgroup\$ Jun 6, 2013 at 14:50

4 Answers 4


GolfScript, 68 67 57 characters

" "/{..+{95&"AEIOUY"?)}:C,1>\{.C!!{96&\(31&@|}*}%\;}%" "*

Input must be given on STDIN. Example (online):

> You!!! I'm a badly written text. Some lunatic guy played with the order of vowels. Please fix me !
Ouy!!! I'm a bydla wrettin text. Semo lanituc gyu plyead with the erdor of vewols. Plaese fix me !

Ruby, 91 90 characters

$><<gets.gsub(/\S+/){|x|x.gsub(r=/[aeiouy]/i){|y|z=$'[r]||x[r];y>?Z?z.downcase: z.upcase}}

Coffeescript, 148 charectars

alert prompt().replace /\S+/g,(x)->x.replace r=/[aeiouy](?=(.*))/gi,(y,z)->((t=z.match r)&&t[0]||x.match(r)[0])[['toLow','toUpp'][y>'Z']+'erCase']()

No ussimtoans, except that "holf-cerract" is a word, and not my sulitoon.


> To test this program, simply enter a long sentence that appears half-broken
  To test this pragrom, sympli enter a long sentence that eppaars holf-brekan

> No MaTtEr HoW mUcH cAsE yOu uSe, It WoRkS
  No MeTtAr HoW mUcH cEsA oUy eSu, It WoRkS
  • \$\begingroup\$ Regarding the Ruby code: 1) spare 2 characters by using $& instead of the second gsub() block's y parameter; 2) spare 1 character by using ?Z instead of 'Z'. \$\endgroup\$
    – manatwork
    Jun 6, 2013 at 16:58
  • \$\begingroup\$ @manatwork $& cannot be used because it is changed before I use it. z=$'[r] changes it. Concerning ?Z - thanks, I totally forgot about this syntax. \$\endgroup\$ Jun 6, 2013 at 17:43
  • \$\begingroup\$ Oops. No idea how I tested it yesterday so appeared to work… \$\endgroup\$
    – manatwork
    Jun 7, 2013 at 7:38

Haskell, 159 characters

Didn't end up quite as short as I'd hoped, but I decided to post it anyway:

import Data.Char
f s=let(v,t)=foldr g(v,[])s in t
g x(v,t)=last$(v,x:t):[(x,c v:t)|c<-[toUpper,toLower],x`elem`map c"AEIOUY"]
main=interact$unwords.map f.words

Ungolfed version:

import Data.Char

rotateVowels :: String -> String
rotateVowels word = result
  where (vowel, result) = foldr step (vowel, []) word
        step ch (vowel, rest)
          | ch `elem` "AEIOUY" = (ch, toUpper vowel : rest)
          | ch `elem` "aeiouy" = (ch, toLower vowel : rest)
          | otherwise          = (vowel, ch : rest)

main = interact $ unwords . map rotateVowels . words

This is a nice example of how lazy evaluation can let you do cool tricks. In rotateVowels, each time a new vowel is found, it is passed on to the left, while replacing it with the one coming from the right. This part of the output from the fold is fed back as the input so that the leftmost vowel becomes the replacement for the rightmost one.

(vowel, result) = foldr step (vowel, []) word
 ^^^^^                        ^^^^^
 this part of the output      is part of the input

Python 2, 172 bytes

for w in input().split():p=[];q=list(w);z=filter(lambda c:c in'aeiouyAEIOUY',q);x=z[1:]+z[:1];print''.join(y in z and[str.upper,str.lower][y>'Z'](x.pop(0))or y for y in q),

Try it online!

  • \$\begingroup\$ @KevinCruijssen fixed it \$\endgroup\$
    – ovs
    Oct 25, 2017 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.