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

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\$
2
  • 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\$
    – anon
    Apr 25, 2018 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, 2018 at 15:44
15
\$\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\$
0
12
\$\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\$
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\$
6
  • \$\begingroup\$ 9 bytes: T`_o`uvUV. \$\endgroup\$
    – Neil
    Apr 23, 2018 at 15:25
  • \$\begingroup\$ This is a remarkably short answer! \$\endgroup\$
    – AJFaraday
    Apr 23, 2018 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\$ Apr 23, 2018 at 15:31
  • 3
    \$\begingroup\$ You can shave off one more, but I can't seem to tie Stax, unfortunately: tio.run/##HYnBDoIwEAXv/… \$\endgroup\$ Apr 23, 2018 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\$ Apr 24, 2018 at 5:12
11
\$\begingroup\$

Perl 5 + -p, 24 23 bytes

y;AEIOUaeiou;EIOUAeioua

Try it online

-1 byte thanks to @DomHastings

\$\endgroup\$
4
  • 2
    \$\begingroup\$ We don't count -p as +1 anymore, instead we consider that this answer is in "Perl 5 + -p". \$\endgroup\$ Apr 23, 2018 at 15:14
  • 2
    \$\begingroup\$ This also works in sed \$\endgroup\$
    – user41805
    Apr 23, 2018 at 18:19
  • 1
    \$\begingroup\$ If you use ; as the delimiter you can save a byte! \$\endgroup\$ Apr 23, 2018 at 19:08
  • \$\begingroup\$ updated, @Cowsquack not anymore \$\endgroup\$ Apr 24, 2018 at 7:38
8
\$\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\$
13
  • 2
    \$\begingroup\$ Seems to be a none standard extension from gcc. I knew it from php and simply tried it. \$\endgroup\$
    – Christoph
    Apr 24, 2018 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\$ Apr 25, 2018 at 8:20
  • 2
    \$\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\$ Apr 25, 2018 at 9:14
  • 3
    \$\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, 2018 at 9:31
  • 3
    \$\begingroup\$ @Rogem Because of the commutative property of addition, a[b]==*(a+b)==*(b+a)==b[a]. Therefore 1[...]==(...)[1] \$\endgroup\$
    – ceilingcat
    Aug 2, 2018 at 22:27
8
\$\begingroup\$

Python 3, 62 59 bytes

lambda x:x.translate(dict(zip(b'aeiouAEIOU','eiouaEIOUA')))

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

EDIT: Saved 3 bytes by using the dict constructor to make the translation table instead of the str#maketrans method

\$\endgroup\$
2
  • \$\begingroup\$ Where does this perform I/O? \$\endgroup\$ Apr 24, 2018 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, 2018 at 16:04
6
\$\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\$

Ruby -p, 31 bytes

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

Try it online!

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

Jelly, 11 bytes

Øcs5ṙ€-Ẏ,Ʋy

Try it online!

\$\endgroup\$
0
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\$
2
  • \$\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\$ Apr 24, 2018 at 3:10
  • \$\begingroup\$ @ArnoldPalmer Thanks! It's ok, I was away and they all missed me :D \$\endgroup\$ Apr 24, 2018 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\$
2
  • \$\begingroup\$ s=>s.replace(/./g,c=>'auoieaAUOIEA'.match(".(?=${c})")||c) \$\endgroup\$
    – tsh
    Apr 24, 2018 at 6:34
  • \$\begingroup\$ Error: only. => unlya \$\endgroup\$
    – l4m2
    Apr 25, 2018 at 1:36
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\$
6
  • 1
    \$\begingroup\$ 23 bytes \$\endgroup\$
    – Shaggy
    Apr 23, 2018 at 17:10
  • 1
    \$\begingroup\$ @Shaggy That doesn't work with capital vowels. \$\endgroup\$
    – Oliver
    Apr 23, 2018 at 17:37
  • 1
    \$\begingroup\$ In that case ... 22 bytes. \$\endgroup\$
    – Shaggy
    Apr 23, 2018 at 18:09
  • 1
    \$\begingroup\$ @Shaggy This is fun...21 bytes \$\endgroup\$
    – Oliver
    Apr 23, 2018 at 18:21
  • 1
    \$\begingroup\$ Nice! I think that's the first time I've seen S.p(f) used. \$\endgroup\$
    – Shaggy
    Apr 23, 2018 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\$
3
  • 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\$ Aug 2, 2018 at 14:12
  • \$\begingroup\$ @KevinCruijssen Thanks ! Isn't that something that was fixed in a recent 05AB1E release ? \$\endgroup\$ Aug 2, 2018 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\$ Aug 2, 2018 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\$
1
  • \$\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\$ Apr 23, 2018 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\$
3
\$\begingroup\$

Vyxal, 9 bytes

k∨:½ƛǓ;∑Ŀ

Try it Online!

Basic transliteration.

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

Elm, 127 123 121 112 103 bytes

9 bytes saved by Hydrazer

f a b=case a of
 c::d::e->if c==b then d else f(d::e)b
 _->b
String.map(String.toList"aeiouaAEIOUA"|>f)

Explanation

This Elm answer is a port of my Haskell answer. I am still learning Elm so there might be a good deal of golfing that can be done. There are a couple of differences here between Elm and Haskell. Elm does not allow multiple declarations of a function so we have to use case instead. Elm is also rather fussy about strings. They are not list of characters and thus have to be treated differently then lists. In fact in order to do any useful of manipulations on strings we pretty much have to just convert them to lists. Aside from that there are a couple of small differences :: is the list cons operator and (|>)=flip($).

You can test the code here, with the following wrapper:

import Html exposing (text)
f a b=case a of
 c::d::e->if c==b then d else f(d::e)b
 _->b
g=String.map(String.toList"aeiouaAEIOUA"|>f)
main=g"It was a dark and stormy night"|>text
\$\endgroup\$
1
  • 1
    \$\begingroup\$ you can just use String String.map / String.toList instead of importing \$\endgroup\$
    – Hydrazer
    Dec 24, 2021 at 17:41
3
\$\begingroup\$

Vyxal, 6 bytes

kv*kV*

Try it Online!

  *    # Ring translate by
kv     # Lowercase vowels
     * # Ring translate by
   kV  # Uppercase vowels
\$\endgroup\$
0
3
\$\begingroup\$

K (ngn/k), 25 bytes

{y^'x[<x]x?y}"UAEIOuaeio"

Try it online!

\$\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\$

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.