Siamo stati qui per Tomis


36

Adoro questo semplice codice, è così divertente leggere parole non abbastanza leggibili dall'uomo e colmare le lacune ...

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.

Le regole sono semplicissime:

  • Accetta del testo come input (caratteri ASCII, lettere maiuscole / minuscole e punteggiatura).
  • Per ogni vocale, ruotala sulla vocale successiva o torna all'inizio.
    • a => e
    • e => i
    • i => o
    • o => u
    • u => a
  • Le vocali maiuscole rimangono maiuscole, le vocali minuscole rimangono minuscole.
  • Stampa il testo dopo queste conversioni.
  • Non c'è bisogno di sostenere gli accenti.
  • Tutti gli altri personaggi dovrebbero rimanere invariati.
  • Prova a farlo nel minor numero di byte.
  • Qualunque vecchia lingua che ti piace.

Casi test

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.

Su:

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.

Nel:

The quick brown fox jumps over the lazy dog.

Su:

Thi qaock bruwn fux jamps uvir thi lezy dug.

Nel:

Home is where the heart is.

Su:

Humi os whiri thi hiert os.

Nel:

Boaty McBoatface

Su:

Buety McBuetfeci

Nel:

AEIOUaeiou

Su:

EIOUAeioua

Nel:

Programming Puzzles And Code Golf

Su:

Prugremmong Pazzlis End Cudi Gulf


4
Hmm. Olde English?
iammax

10
Still an easier read than Beowulf.
Smeato

4
Looks like a kiwi-translater to me.
Magoo

1
I like how “evil” when ciphers to “ivol”, is effectively pronounced the same way.
Enrico Borba

Risposte:


11

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.


22

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."


1
I'm genuinely shocked that SQL is even close to competitive for this. Also, that's a cool function! Thanks for telling us :)
Fund Monica's Lawsuit

@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.
BradC


14

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.


12

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.


9 bytes: T`_o`uvUV.
Neil

This is a remarkably short answer!
AJFaraday

@Neil clever, thanks! I thought putting an _ in the from set would treat it literally, but it looks like it doesn't do that.
FryAmTheEggman

3
You can shave off one more, but I can't seem to tie Stax, unfortunately: tio.run/##HYnBDoIwEAXv/…
Martin Ender

@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.
FryAmTheEggman


6

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.


Where does this perform I/O?
reinierpost

@reinierpost It's a function. The input is via the x parameter. In python, lambda functions don't need a return statement.
mypetlion

6

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
}

1
Seems to be a none standard extension from gcc. I knew it from php and simply tried it.
Christoph

1
@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///…
O.O.Balance

1
@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.
Peter Cordes

2
@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.
Christoph

1
@Rogem Because of the commutative property of addition, a[b]==*(a+b)==*(b+a)==b[a]. Therefore 1[...]==(...)[1]
ceilingcat



5

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!


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.
Arnold Palmer

@ArnoldPalmer Thanks! It's ok, I was away and they all missed me :D
Dead Possum

5

JavaScript (ES6), 60 bytes

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

Try it online!


s=>s.replace(/./g,c=>'auoieaAUOIEA'.match(".(?=${c})")||c)
tsh

Error: only. => unlya
l4m2


4

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.


4

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

4

05AB1E, 14 13 11 bytes

žMDÀ‡žMuDÀ‡

Try it online!


1
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.
Kevin Cruijssen

@KevinCruijssen Thanks ! Isn't that something that was fixed in a recent 05AB1E release ?
Kaldo

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.
Kevin Cruijssen


3

APL+WIN, 55 bytes

Prompts for input string:

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

3

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")

3

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.


3

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

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
Peter Taylor


2

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)));


2

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

2

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.


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.
Shaggy

2
@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.
Davіd

1
Thanks, @David - that's my "something new" for PHP today :)
Shaggy

2

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"]

2

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)

2

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
        )
    );
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.