36
\$\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\$
  • 20
    \$\begingroup\$ A.k.a. The Great Vowel Shift \$\endgroup\$ – Angs Apr 23 '18 at 18:27
  • 4
    \$\begingroup\$ Hmm. Olde English? \$\endgroup\$ – iammax Apr 24 '18 at 1:26
  • 10
    \$\begingroup\$ Still an easier read than Beowulf. \$\endgroup\$ – Smeato Apr 24 '18 at 10:50
  • 4
    \$\begingroup\$ Looks like a kiwi-translater to me. \$\endgroup\$ – Magoo Apr 24 '18 at 16:30
  • 1
    \$\begingroup\$ I like how “evil” when ciphers to “ivol”, is effectively pronounced the same way. \$\endgroup\$ – Enrico Borba May 3 '18 at 6:34

37 Answers 37

11
\$\begingroup\$

Stax, 7 bytes

öΦΣòC└∞

Run and debug it

Try it online!

Explanation (unpacked)

Vv:tVV:t
Vv:t           #Push aeiou and ring translate it to input
    VV:t       #Push AEIOU and ring translate it to input

Might be able to save more, will keep trying.

\$\endgroup\$
22
\$\begingroup\$

MS-SQL, 51 Bytes

Works on SQL 2017 or above:

SELECT TRANSLATE(v,'AEIOUaeiou','EIOUAeioua')FROM t

The new function TRANSLATE performs individual character replacement, so is ideally suited for this challenge.

Input is via a pre-existing table t with varchar column v, per our IO rules.

In this case the table must be created using a case-sensitive collation, either by running on a case-sensitive server, or by using the COLLATE keyword (not counted toward character total):

CREATE TABLE t(v varchar(max) COLLATE Latin1_General_CS_AS)

EDIT: SSMS may cut off the lengthy quote above when returning the result in a "results to text" window, this is a client setting, not a bug in my program.

To fix, go to Tools > Options > Query Results > SQL Server > Results to Text and increase the "Maximum number of characters displayed in each column."

\$\endgroup\$
  • 1
    \$\begingroup\$ I'm genuinely shocked that SQL is even close to competitive for this. Also, that's a cool function! Thanks for telling us :) \$\endgroup\$ – Nic Hartley Apr 25 '18 at 14:40
  • \$\begingroup\$ @NicHartley Yeah, they seem to add a couple useful functions each version. You can nest it with REPLACE for some tricks as well: REPLACE(TRANSLATE(v,'1234567890','xxxxxxxxxx'),'x','') to eliminate all numerals from a string, for example. Still long, but much shorter than 10 nested REPLACEs. \$\endgroup\$ – BradC Apr 25 '18 at 15:44
14
\$\begingroup\$

Bash + coreutils, 24

tr aeiouAEIOU eiouaEIOUA

Try it online!

\$\endgroup\$
14
\$\begingroup\$

Haskell, 52 bytes

(a:b)!c|a/=c=b!c|1>0=b!!0
a!b=b
map("aeiouaAEIOUA"!)

Try it online!

Lynn saved me two bytes by pointing out that !!0 is shorter than head.

Explanation

If you have never coded in Haskell this will probably look like a pile of jibberish. So first let's ungolf it and then break it down:

(a:b)!c
 |   a/=c   = b!c
 |otherwise = b!!0
a!b=b
map("aeiouaAEIOUA"!)

First we have a function !, which takes a string s and a character c. Our first pattern match catches accepts input if the string is non-empty. If the string is non-empty we compare its first character to c. If it's first character is not equal to c we toss it and call ! again with the remainder of the string and c. If it is equal we return the second character in the string.

Our next pattern match catches the string in all other cases, that is if the string is empty. In this case we just return c.

All in all this function takes a character c and a string s and returns the character after the first occurrence of c in s. If we pass this with aeiouaAEIOUA it will perform our cipher on a single character. To make our whole function we ought to map this across the string.

\$\endgroup\$
12
\$\begingroup\$

Retina, 10 9 8 bytes

T`uo`vVA

Try it online!

Saved 1 byte thanks to Neil! And another byte thanks to Martin!

The new version of retina has vowel classes, which makes the result a bit shorter. The transliteration also makes use of the "other" class. So the to class looks like "aeiouAEIOUA" while the from class looks like "uaeiouAEIOUA"

This doesn't cause any problems since the second u mapping to A will never be done since u was already mapped to a.

\$\endgroup\$
  • \$\begingroup\$ 9 bytes: T`_o`uvUV. \$\endgroup\$ – Neil Apr 23 '18 at 15:25
  • \$\begingroup\$ This is a remarkably short answer! \$\endgroup\$ – AJFaraday Apr 23 '18 at 15:25
  • \$\begingroup\$ @Neil clever, thanks! I thought putting an _ in the from set would treat it literally, but it looks like it doesn't do that. \$\endgroup\$ – FryAmTheEggman Apr 23 '18 at 15:31
  • 3
    \$\begingroup\$ You can shave off one more, but I can't seem to tie Stax, unfortunately: tio.run/##HYnBDoIwEAXv/… \$\endgroup\$ – Martin Ender Apr 23 '18 at 22:26
  • \$\begingroup\$ @MartinEnder Thanks! That's a clever setup, mixing between the two. I haven't tried using Y much yet so I'll give that a shot tomorrow. \$\endgroup\$ – FryAmTheEggman Apr 24 '18 at 5:12
9
\$\begingroup\$

Perl 5 + -p, 24 23 bytes

y;AEIOUaeiou;EIOUAeioua

Try it online

-1 byte thanks to @DomHastings

\$\endgroup\$
  • 1
    \$\begingroup\$ We don't count -p as +1 anymore, instead we consider that this answer is in "Perl 5 + -p". \$\endgroup\$ – Erik the Outgolfer Apr 23 '18 at 15:14
  • 1
    \$\begingroup\$ This also works in sed \$\endgroup\$ – Cows quack Apr 23 '18 at 18:19
  • 1
    \$\begingroup\$ If you use ; as the delimiter you can save a byte! \$\endgroup\$ – Dom Hastings Apr 23 '18 at 19:08
  • \$\begingroup\$ updated, @Cowsquack not anymore \$\endgroup\$ – Nahuel Fouilleul Apr 24 '18 at 7:38
6
\$\begingroup\$

Python 3, 62 bytes

lambda x:x.translate(str.maketrans('aeiouAEIOU','eiouaEIOUA'))

Make a translation table (dictionary) with str's static str.maketrans method. Translate relevant characters to their destination character.

\$\endgroup\$
  • \$\begingroup\$ Where does this perform I/O? \$\endgroup\$ – reinierpost Apr 24 '18 at 14:42
  • \$\begingroup\$ @reinierpost It's a function. The input is via the x parameter. In python, lambda functions don't need a return statement. \$\endgroup\$ – mypetlion Apr 24 '18 at 16:04
6
\$\begingroup\$

C, 85 76 67 65 64 bytes

f(char*c){for(;*c;)putchar(1[index("AEIOUAaeioua",*c++)?:c-2]);}

Port of Kevin Cruijssen's Java answer. Try it online here.

Thanks to Kevin Cruijssen for golfing 9 bytes, to Christoph for golfing 11 bytes and to ceilingcat for golfing 1 byte.

Ungolfed version:

f(char* c) { // function taking a char array as parameter and implicitly returning an unused int
    for(; *c ;) // loop over the input
        putchar(1 [index("AEIOUAaeioua", * c++) ?: c-2]); // find the first pointer to the current char in the vowels string, NULL if not present; if it's not NULL, print the next vowel, otherwise just print the char
}
\$\endgroup\$
  • 1
    \$\begingroup\$ Seems to be a none standard extension from gcc. I knew it from php and simply tried it. \$\endgroup\$ – Christoph Apr 24 '18 at 14:14
  • 1
    \$\begingroup\$ @Christoph I like your use of recursion, but I'm not sure we can output a trailing \0. Also, this does not work when compiled with clang: tio.run/##S9ZNzknMS///… \$\endgroup\$ – O.O.Balance Apr 25 '18 at 8:20
  • 1
    \$\begingroup\$ @Christoph: I was curious where the undefined behaviour was, so I debugged the clang version, after ungolfing it some more. const char *res = strchr("AEIOU...", 0) returns a pointer to terminator in the string literal. putchar(res[1]) reads past the end of the string literal. With gcc it apparently happens to find another zero byte and it happens to work, but with clang it gets a 73 'I' (probably from main's string literal, "It was...", but I didn't check the asm). So putchar doesn't return 0, and we eventually segfault when *c++ reads an unmapped page. \$\endgroup\$ – Peter Cordes Apr 25 '18 at 9:14
  • 2
    \$\begingroup\$ @PeterCordes yeah I found out about it here after having a suspicion. Anyway here another 2 bytes saved f(char*c){for(;*c;)putchar(1[strchr("AEIOUAaeioua",*c++)?:c-2]);}. That's all for now I guess. \$\endgroup\$ – Christoph Apr 25 '18 at 9:31
  • 1
    \$\begingroup\$ @Rogem Because of the commutative property of addition, a[b]==*(a+b)==*(b+a)==b[a]. Therefore 1[...]==(...)[1] \$\endgroup\$ – ceilingcat Aug 2 '18 at 22:27
5
\$\begingroup\$

R, 43 bytes

chartr("AEIOUaeiou","EIOUAeioua",scan(,""))

Try it online!

Here's my solution wrapped in a cat to get it to print out more nicely: Try it online!

\$\endgroup\$
5
\$\begingroup\$

Jelly, 11 bytes

Øcs5ṙ€-Ẏ,Ʋy

Try it online!

\$\endgroup\$
5
\$\begingroup\$

Python 2, 79 68 67 bytes

-1 byte thanks to @ArnoldPalmer

V='uaeiouAEIOUA'
print''.join((V[1:]+c)[V.find(c)]for c in input())

Try it online!

\$\endgroup\$
  • \$\begingroup\$ 67 bytes. Also, sorry if you got flooded with notifications, I haven't posted a comment in a while and forgot how to do it. \$\endgroup\$ – Arnold Palmer Apr 24 '18 at 3:10
  • \$\begingroup\$ @ArnoldPalmer Thanks! It's ok, I was away and they all missed me :D \$\endgroup\$ – Dead Possum Apr 24 '18 at 9:55
5
\$\begingroup\$

JavaScript (ES6), 60 bytes

s=>s.replace(/./g,c=>(S='aeiouaAEIOUA'+c+c)[S.indexOf(c)+1])

Try it online!

\$\endgroup\$
  • \$\begingroup\$ s=>s.replace(/./g,c=>'auoieaAUOIEA'.match(".(?=${c})")||c) \$\endgroup\$ – tsh Apr 24 '18 at 6:34
  • \$\begingroup\$ Error: only. => unlya \$\endgroup\$ – l4m2 Apr 25 '18 at 1:36
4
\$\begingroup\$

Ruby -p, 31 bytes

$_.tr!"AEIOUaeiou","EIOUAeioua"

Try it online!

\$\endgroup\$
4
\$\begingroup\$

Pyth, 17 bytes

em=.rQdrB"aeiou"1

Try it here

em=.rQdrB"aeiou"1
 m                  For each string...
       rB"aeiou"1   ... in ['aeiou', 'AEIOU']...
  =.rQd             ... cyclically rotate the characters in the input.
e                   Take the last.
\$\endgroup\$
4
\$\begingroup\$

Japt 2.0, 25 21 bytes

I had fun golfing this one with Shaggy.

r\v@=`aeia`pu)g1+UbX

Run it here.

\$\endgroup\$
  • 1
    \$\begingroup\$ 23 bytes \$\endgroup\$ – Shaggy Apr 23 '18 at 17:10
  • 1
    \$\begingroup\$ @Shaggy That doesn't work with capital vowels. \$\endgroup\$ – Oliver Apr 23 '18 at 17:37
  • 1
    \$\begingroup\$ In that case ... 22 bytes. \$\endgroup\$ – Shaggy Apr 23 '18 at 18:09
  • 1
    \$\begingroup\$ @Shaggy This is fun...21 bytes \$\endgroup\$ – Oliver Apr 23 '18 at 18:21
  • 1
    \$\begingroup\$ Nice! I think that's the first time I've seen S.p(f) used. \$\endgroup\$ – Shaggy Apr 23 '18 at 18:26
4
\$\begingroup\$

Java 10, 97 87 bytes

s->{for(var c:s){var t="AEIOUAaeioua"+c+c;System.out.print(t.charAt(t.indexOf(c)+1));}}

-10 bytes after being inspired by @Arnauld's JavaScript answer (his 60-bytes version).

Try it online.

Explanation:

s->{                         // Method with character-array parameter and no return-type
  for(var c:s){              //  Loop over the input characters
    var t="AEIOUAaeioua"     //  Temp-String containing the order of vowels 
                             //  (including additional 'A' and 'a'),
          +c+c;              //  appended with two times the current character
    System.out.print(        //  Print:
      t.charAt(              //   The character in String `t` at index:
         t.indexOf(c)+1));}} //    The (first) index of the current character in `t` + 1
\$\endgroup\$
4
\$\begingroup\$

05AB1E, 14 13 11 bytes

žMDÀ‡žMuDÀ‡

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ You can save two bytes by simply taking the input as a multi-line string, so there is no need for the | and »: Try it online: 11 bytes. \$\endgroup\$ – Kevin Cruijssen Aug 2 '18 at 14:12
  • \$\begingroup\$ @KevinCruijssen Thanks ! Isn't that something that was fixed in a recent 05AB1E release ? \$\endgroup\$ – Kaldo Aug 2 '18 at 14:39
  • \$\begingroup\$ No idea tbh. Only started 05AB1E since about the start of this year. You could ask @Adnan in the 05AB1E chat when the feature was added if you want to know. \$\endgroup\$ – Kevin Cruijssen Aug 2 '18 at 14:41
3
\$\begingroup\$

Retina 0.8.2, 20 bytes

T`_o`A\EI\OUAaei\oua

Try it online! Link includes test cases.

\$\endgroup\$
3
\$\begingroup\$

APL+WIN, 55 bytes

Prompts for input string:

i←(10≥n←'AEIOUaeiou'⍳s)/⍳⍴s←⎕⋄s[i]←'EIOUAeioua'[n~11]⋄s
\$\endgroup\$
3
\$\begingroup\$

Mumps, 38 bytes

R T W $TR(T,"AEIOUaeiou","EIOUAeioua")

Mumps doesn't normally add a carriage return, as I didn't see a requirement to separate input from output it does look a bit weird on first run. For example, the output for the last test case looks like this:

Programming Puzzles And Code GolfPrugremmong Pazzlis End Cudi Gulf

If you did want to add a carriage return, add two bytes thusly:

R T W !,$TR(T,"AEIOUaeiou","EIOUAeioua")
\$\endgroup\$
3
\$\begingroup\$

Vim + tpope/vim-abolish, 30 bytes

:%S/{a,e,i,o,u}/{e,i,o,u,a}/g<cr>

Alternate solution, also 30 bytes:

Oe,i,o,u<esc>|D:%s/{a,<C-r>"}/{<C-r>",a}/g

According to meta, vim answers can use plugins with no byte penalty. This is not a vim answer, but a vim + abolish answer.


Abolish is an extremely useful plugin. This section of the README nicely describes how this command (the Subvert command) works.

\$\endgroup\$
3
\$\begingroup\$

CJam, 29 19 bytes

q"aeioua"_eu+_1m<er

Try it online!

-10 bytes thanks to @Peter Taylor

Explanation:

q                       # take all input
 "aeioua"               # push vowel pairs
         _eu            # duplicate, uppercase
            +_          # concatenate, duplicate again
              1m<       # rotate left by 1
                 er     # transliterate
\$\endgroup\$
  • \$\begingroup\$ Although the question isn't specific about the input, I think you should probably use q rather than l to take input. The first test case appears to be multi-line. Also you can shorten "eioua" to _1m<. In fact, you can go further and golf this to q"aeioua"_eu+_1m<er \$\endgroup\$ – Peter Taylor Apr 23 '18 at 21:07
3
\$\begingroup\$

AutoHotkey, 24 bytes

AuotHotkey automatically replaces letters in a case sensitive manner.

a::e
e::i
i::o
o::u
u::a
\$\endgroup\$
2
\$\begingroup\$

PHP, 90 Bytes

Try it online

Code

function f($s){echo strtr($s,array_combine(str_split(UuAaEeIiOo),str_split(AaEeIiOoUu)));}

Explanation

function f($s){
 echo strtr(
       $s,                          #The string to operate
       array_combine(               #combining arrays
            str_split(UuAaEeIiOo),  #splitting this strings
            str_split(AaEeIiOoUu))
              # With array combine php creates an array like
              # ["U"=>"A", "a"=>"e"....and so on]
              # strtr can replace strings in a string, using an array with 
              # the values to replace and with what replace each value.
 );
}

75 Bytes if ran with php -r using $argv

<?=strtr($argv,array_combine(str_split(UuAaEeIiOo),str_split(AaEeIiOoUu)));
\$\endgroup\$
2
\$\begingroup\$

J, 33 bytes

rplc'aeiou',&((;"0)1&|.)'AEIOU'"1

Try it online!

\$\endgroup\$
2
\$\begingroup\$

str, 18 bytes

[aeiouaAEIOUA]#D#U

Try it online!

Explanation

                       implicit: over each character of the input:
[aeiouaAEIOUA]#D#U
[            ]         push this string
              #D       set this to the operation domain
                #U     set the charcter to the next character in the domain
\$\endgroup\$
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\$
  • \$\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 '18 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\$ – Davіd Apr 23 '18 at 16:05
  • 1
    \$\begingroup\$ Thanks, @David - that's my "something new" for PHP today :) \$\endgroup\$ – Shaggy Apr 23 '18 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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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