43
\$\begingroup\$

I just love this simple cypher, it's so fun reading not-quite human-readable words and filling the gaps...

Ot wes thi bist uf tomis, ot wes thi wurst uf tomis, 
ot wes thi egi uf wosdum, ot wes thi egi uf fuuloshniss, 
ot wes thi ipuch uf biloif, ot wes thi ipuch uf oncridaloty, 
ot wes thi siesun uf loght, ot wes thi siesun uf derkniss, 
ot wes thi sprong uf hupi, ot wes thi wontir uf dispeor, 
wi hed ivirythong bifuri as, wi hed nuthong bifuri as, 
wi wiri ell guong dorict tu hievin, wi wiri ell guong dorict thi uthir wey – 
on shurt, thi piroud wes su fer loki thi prisint piroud, 
thet sumi uf ots nuosoist eathurotois onsostid un ots biong riciovid, 
fur guud ur fur ivol, on thi sapirletovi digrii uf cumperosun unly.

The rules are super-simple:

  • Accept some text as input (ascii characters, upper/lower case letters and punctuation).
  • For each vowel, rotate it to the next vowel, or back to the start.
    • a => e
    • e => i
    • i => o
    • o => u
    • u => a
  • Upper case vowels stay upper case, lower case vowels stay lower case.
  • Output the text after these conversions.
  • No need to support accents.
  • The all other characters should remain unchanged.
  • Try to do it in the smallest number of bytes.
  • Any old language you like.

Test Cases

It was the best of times, it was the worst of times,
it was the age of wisdom, it was the age of foolishness,
it was the epoch of belief, it was the epoch of incredulity,
it was the season of light, it was the season of darkness,
it was the spring of hope, it was the winter of despair,
we had everything before us, we had nothing before us,
we were all going direct to heaven, we were all going direct the other way –
in short, the period was so far like the present period,
that some of its noisiest authorities insisted on its being received,
for good or for evil, in the superlative degree of comparison only.

Out:

Ot wes thi bist uf tomis, ot wes thi wurst uf tomis, 
ot wes thi egi uf wosdum, ot wes thi egi uf fuuloshniss, 
ot wes thi ipuch uf biloif, ot wes thi ipuch uf oncridaloty, 
ot wes thi siesun uf loght, ot wes thi siesun uf derkniss, 
ot wes thi sprong uf hupi, ot wes thi wontir uf dispeor, 
wi hed ivirythong bifuri as, wi hed nuthong bifuri as, 
wi wiri ell guong dorict tu hievin, wi wiri ell guong dorict thi uthir wey – 
on shurt, thi piroud wes su fer loki thi prisint piroud, 
thet sumi uf ots nuosoist eathurotois onsostid un ots biong riciovid, 
fur guud ur fur ivol, on thi sapirletovi digrii uf cumperosun unly.

In:

The quick brown fox jumps over the lazy dog.

Out:

Thi qaock bruwn fux jamps uvir thi lezy dug.

In:

Home is where the heart is.

Out:

Humi os whiri thi hiert os.

In:

Boaty McBoatface

Out:

Buety McBuetfeci

In:

AEIOUaeiou

Out:

EIOUAeioua

In:

Programming Puzzles And Code Golf

Out:

Prugremmong Pazzlis End Cudi Gulf
\$\endgroup\$
10
  • 27
    \$\begingroup\$ A.k.a. The Great Vowel Shift \$\endgroup\$
    – Angs
    Apr 23, 2018 at 18:27
  • 5
    \$\begingroup\$ Hmm. Olde English? \$\endgroup\$
    – iammax
    Apr 24, 2018 at 1:26
  • 11
    \$\begingroup\$ Still an easier read than Beowulf. \$\endgroup\$
    – Smeato
    Apr 24, 2018 at 10:50
  • 4
    \$\begingroup\$ Looks like a kiwi-translater to me. \$\endgroup\$
    – Magoo
    Apr 24, 2018 at 16:30
  • 3
    \$\begingroup\$ I like how “evil” when ciphers to “ivol”, is effectively pronounced the same way. \$\endgroup\$ May 3, 2018 at 6:34

41 Answers 41

1
2
2
\$\begingroup\$

PHP, 38 bytes

Quite simple, not very creative, uses strtr to replace the vowels:

<?=strtr($argn,aeiouAEIOU,eiouaEIOUA);

Run with echo '<input>' | php -nF <filename> or Try it online.

\$\endgroup\$
3
  • \$\begingroup\$ Does this not assume that the input is assigned to the predefined variable argn? If so then that's not valid; you'd need to pass the string as an argument and use $argv1] instead. \$\endgroup\$
    – Shaggy
    Apr 23, 2018 at 16:01
  • 2
    \$\begingroup\$ @Shaggy No, if you run it with the -F flag, then it works with input on the command line. From the PHP docs on options: -F --process-file PHP file to execute for every input line. Added in PHP 5. The Try it online variable defining is just because some people don't have PHP installed locally, and I couldn't get the -F flag working in TIO. \$\endgroup\$
    – Ethan
    Apr 23, 2018 at 16:05
  • 1
    \$\begingroup\$ Thanks, @David - that's my "something new" for PHP today :) \$\endgroup\$
    – Shaggy
    Apr 23, 2018 at 16:06
2
\$\begingroup\$

q/kdb+, 36 33 bytes

Solution:

{(v,2#x)1+(v:"aeiouaAEIOUA")?x}@'

Examples:

q){(v,2#x)1+(v:"aeiouaAEIOUA")?x}@'"AEIOUaeiou"
"EIOUAeioua
q){(v,2#x)1+(v:"aeiouaAEIOUA")?x}@'"Programming Puzzles And Code Golf"
"Prugremmong Pazzlis End Cudi Gulf"

Explanation:

Figure out index of vowels, add one to push along to the next and index in. Still think this approach can be significantly improved...

{(v,2#x)1+(v:"aeiouaAEIOUA")?x}@' / the solution
{                             }@' / apply lambda to each character of input
                            ?x    / look up x in...
          (                )      / do together
             "aeiouaAEIOUA"       / lookup list
           v:                     / save as v
        1+                        / add one
 (     )                          / do together
    2#x                           / take 2 copies of x
  v,                              / prepend v

Bonus:

My old **36 byte(()) solution which I think is quite cool, but need to golf down the lists to make it competetive:

ssr/[;"uoiea%UOIEA%";"%uoiea%UOIEA"]
\$\endgroup\$
2
\$\begingroup\$

Charcoal, 35 bytes

UT≔AUOIEAauoieaσF¹¹⊞υ➙§σ⊕ι§σι▷SR⟦Sυ

Try it online!

Naive method.

Explanation:

UT                                         Set trim option to on, so output won't be a rectangle
    ≔AUOIEAauoieaσ                          Assign "AUIOEAauioea" to s
                   F¹¹                      For i (ι) from 0 to 10
                       ⊞υ                   Push to u (initially empty list)
                          ➙                 Rule of:
                            §σ⊕ι            S[i + 1]
                                 §σι         to S[i]. This is so a->A gets overwriteen by a->e
                                    ▷SR⟦Sυ  Replace input as string using u (now a list of rules)
\$\endgroup\$
2
\$\begingroup\$

PHP, 76 bytes.

$s=strtr($s,array_combine(str_split("aeiouAEIOU"),str_split("eiouaEIOUA")));

Check it out!

This was the shortest I was able to do this in PHP.

$s = //overwrite $s variable ($s should be a defined string or input)
    strtr(  //strtr replaces key => value pairs from arrays in a string
        $s, //the string we are converting
        array_combine( //create an array with key value pairs, key should be original vowel letter and value should be it's replacement
            str_split("aeiouAEIOU") //turn vowels (lower and upper) into an array
            ,str_split("eiouaEIOUA") //turn vowel replacements into an array
        )
    );
\$\endgroup\$
2
\$\begingroup\$

MATL, 15 bytes

,@11+Y2t1_YSXE]

Try it on MATL Online

\$\endgroup\$
1
\$\begingroup\$

Python 3: 148 126 121 Bytes

Fixed code, saved 22 bytes by not using a flag for case management

Saved 5 bytes by removing uneeded spaces

import re;print(re.sub('a|A',r"e",re.sub('e|E',r"i",re.sub('i|I',r"o",re.sub('o|O',r"u",re.sub('u|U',r"a",input()))))))

Definitely can be improved if i can figure out how to group patters with their respective groups of replaces. Will probaly save 90+ bytes

\$\endgroup\$
1
\$\begingroup\$

Tcl, 56 bytes

proc C s {string map [split aeeiioouuaAEEIIOOUUA ""] $s}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

APL (Dyalog Classic), 54 50 bytes

{(X,⍨1⌽v)[X⍳⍨v,X←(⍵,⍨1⌽w)[⍵⍳⍨⍵,⍨w←819⌶v←'AEIOU']]}

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ Very good test case generation! \$\endgroup\$
    – AJFaraday
    Apr 24, 2018 at 21:23
  • \$\begingroup\$ I should've done "aeiouAEIOUbcd!?" or something, but thanks! \$\endgroup\$
    – Adalynn
    Apr 24, 2018 at 21:26
  • \$\begingroup\$ It’s a much more satisfying sentence, tho. \$\endgroup\$
    – AJFaraday
    Apr 24, 2018 at 21:27
  • \$\begingroup\$ Or at least have added a small a. \$\endgroup\$
    – Adalynn
    Apr 24, 2018 at 21:36
  • \$\begingroup\$ Well, “worlda” sounds odd, but “wurlde” sounds very olde English. \$\endgroup\$
    – AJFaraday
    Apr 24, 2018 at 22:46
1
\$\begingroup\$

sed, 24 bytes

y/aeiouAEIOU/eiouaEIOUA/

\$\endgroup\$
1
\$\begingroup\$

GolfScript, 34 bytes

{.'aeiouAEIOU'?"eiouaEIOUA0"=\or}%

Where 0 denotes a null byte. In the TIO link, I had to use \0, so it is one byte longer.

Try it online!

Simple transliteration. I tried to build the two strings but it was 15 bytes longer.

\$\endgroup\$
1
\$\begingroup\$

Knight, 85 bytes

;=xP Wx;=v"aeiouAEIOU";=iF;W&v!?AxAv;=i+1i=vSvF1"";O+|G"eiouaEIOUA"iT A Ax"\"=xSxF1""

Try it online!

\$\endgroup\$
1
2

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.