6
\$\begingroup\$

The Task

Your task is to create a program or a function that, given a sentence, outputs it translated to the Farfallino language. 'Y' is treated as a consonant.

The usual rules for farfallino alphabet are based on the substitution of each vowel with a 3 letter sequence where the vowel itself is repeated with an interceding f.

house → hofoufusefe
lake → lafakefe
star → stafar
king → kifing
search → sefeafarch

More examples:

Hello World

Hefellofo Woforld

Code golfs are nice, yuppy!

Cofodefe gofolfs afarefe nificefe, yufuppy!

When you come across a double vowel syllable (the vowels must match, like door, boots, reed, etc.) you must omit the 2nd vowel. This rule is mandatory

Cool game

WRONG: Cofoofol gafamefe

RIGHT: Cofofol gafamefe

More examples, again:

Aardvark → Afafardvafark
Artisan → Afartifisafan
ASCII → AfaSCIfifi
NASA → NAfaSAfa
Oobleck → Ofofobleck
I'M DEAD! → Ifi'M DEfeAfaD!
Abc → Afabc

Input

Your input must be an ASCII string.

>2 consecutive vowels are not special. You have to handle 2 consecutive vowels:

AAAH → AfafaAfaH
AAAAH → AfafaAfafaH

How to win

The shortest source code in bytes for each language wins.

1, 2, 3... go!

\$\endgroup\$

closed as unclear what you're asking by DJMcMayhem May 30 '18 at 17:50

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    \$\begingroup\$ Reminds me of l'argot louchébem \$\endgroup\$ – JayCe May 28 '18 at 19:55
  • 2
    \$\begingroup\$ Very similar. \$\endgroup\$ – nimi May 28 '18 at 20:16
  • 5
    \$\begingroup\$ Do we need to handle upper and lowercase letters? And if so, what should we get for OoOoO? \$\endgroup\$ – Mnemonic May 28 '18 at 20:25
  • 8
    \$\begingroup\$ Too bad the sandbox wasn't used first. This one could have been whipped into shape in advance. I don't think the challenge is interesting enough without the double vowel requirement. It's a basic regular expression/substitution without much room for ingenuity. \$\endgroup\$ – ngm May 28 '18 at 20:41
  • 4
    \$\begingroup\$ Changing a challenge's spec to invalidate existing solutions is an automatic -1 from me. I'd -1 a second time, if I could, for not bothering to inform those that had posted those solutions. \$\endgroup\$ – Shaggy May 29 '18 at 18:32

14 Answers 14

10
\$\begingroup\$

Japt, v2.0a0, 7 bytes

r\v_²íf

Try it


Explanation

r           :Replace
 \v         :/[AEIOU]/gi
   _        :Pass each match through a function
    ²       :  Duplicate
     íf     :  Interleave "f"

Note: This solution was posted before the "bonus" of handling double vowels was made a requirement and before the (apparent) requirement that when repeating an uppercase vowel the second occurrence should be lowercased. I don't much feel like wasting time on a challenge whose spec is constantly changing and invalidating the solutions that have already been posted, nor do I feel I should be expected to sacrifice 90 rep by deleting a solution that was valid at the time of posting.

\$\endgroup\$
  • \$\begingroup\$ Whoops, you answered before it was made mandatory. My bad. \$\endgroup\$ – Khuldraeseth na'Barya May 29 '18 at 18:11
  • 1
    \$\begingroup\$ Unfortunately, the double-vowel rule became mandatory, invalidating this answer. \$\endgroup\$ – Dennis May 30 '18 at 13:28
6
\$\begingroup\$

JavaScript (ES6), 67 bytes

f=
s=>s.replace(/([aeiou])\1*/gi,s=>[s[0],...s.toLowerCase()].join`f`)
<input oninput=o.textContent=f(this.value)><pre id=o>

Includes the double vowel handling. Edit: Includes upper case too. Try Aardvark.

\$\endgroup\$
  • \$\begingroup\$ @3D1T0R Well, I was waiting for clarification from the OP, but I guess this will do for now. \$\endgroup\$ – Neil May 29 '18 at 17:59
  • 2
    \$\begingroup\$ It would be nice to have it edited into the post, but OP did say in a comment @ngn I'd say the first one si the correct one. The input entered shouldn't impact the program imho so keep it simple referring to ngn's comment @Cris how does "Abc" translate to Farfallino? "Afabc", "AfAbc", or "AFAbc"?. I'd take this as meaning that the way you now treat them is correct. \$\endgroup\$ – 3D1T0R May 29 '18 at 18:50
5
\$\begingroup\$

05AB1E, 27 bytes

'fžMDu+DŠδ.ø˜‡γεDÙlžMsåiÙ}?

Try it online!

Just a temporary fix for handling double vowels. I'll try to shorten this after my finals. Boo to rule changes!

05AB1E, 14 bytes

'fžMDu+DŠδ.ø˜‡

Try it online!

If we only need to handle lowercase input, then this is 11 bytes.

How it works

  • 'f pushes the character literal f to the stack
  • žMDu+D yields aeiouAEIOU; in the 11-byte version, it pushes aeiou to the stack; the leading D duplicates it (that is, it pushes two copies of it to the stack).
  • Šδ.ø˜ surrounds f with each vowel in the second copy
  • performs the transliteration of the input from the first copy of the vowels to the second copy, the one in which all vowels surround a single f
\$\endgroup\$
  • 1
    \$\begingroup\$ This is incorrect for "Cool Game". It produces "Cofoofol gafamefe" instead of "Cofofol gafamefe". \$\endgroup\$ – recursive May 29 '18 at 22:48
  • \$\begingroup\$ I see that is due to spec changes. I hadn't noticed the changes before, I will fix this later when I get back home. \$\endgroup\$ – Mr. Xcoder May 30 '18 at 4:06
  • \$\begingroup\$ I wouldn't have mentioned it if I'd noticed the change at the time. So it goes. \$\endgroup\$ – recursive May 30 '18 at 4:12
3
\$\begingroup\$

Jelly, 22 bytes

;”f;ƊeØc$¡€F;⁷ḟ⁹fØc¤¥Ɲ

Try it online!

Handles the extra (now required) feature.

Jelly, 11 bytes

;”f;ƊeØc$¡€

Try it online!

Doesn't handle the double vowel feature.

;”f;ƊeØc$¡€
          €  For each character in the input, do the following.
         ¡   If:
     e       the character is in...
      Øc     the list 'aeiouAEIOU'
        $    (connects e and Øc into a single monad)
             then:
;            append
 ”f          the letter f
   ;         and append the initial character.
    Ɗ        Group ;”f; into a single monad.
\$\endgroup\$
3
\$\begingroup\$

Retina, 34 30 bytes

i`[aeiou]
$0f$l
([aeiou])\1
$1

Try it online!

First time using Retina...

-2 bytes thanks to Kevin Cruijssen
-2 bytes thanks to PunPun1000

\$\endgroup\$
  • \$\begingroup\$ You can remove the two trailing new-lines to make it 32 bytes. Everything else would be the same as how I would post it if you hadn't already, so +1 from me. \$\endgroup\$ – Kevin Cruijssen May 29 '18 at 9:55
  • \$\begingroup\$ @KevinCruijssen Thanks! \$\endgroup\$ – Giacomo Garabello May 29 '18 at 9:58
  • \$\begingroup\$ You can remove the parentheses in the first line and change the $1 to $0 in the second line (entire match instead of first group) for -2 bytes \$\endgroup\$ – PunPun1000 May 29 '18 at 16:32
  • \$\begingroup\$ You'll probably want to add a $l to fix the Abc case. \$\endgroup\$ – Neil May 30 '18 at 0:27
  • \$\begingroup\$ @PunPun1000 Thank you for the tip! \$\endgroup\$ – Giacomo Garabello May 30 '18 at 6:43
2
\$\begingroup\$

Python 2, 80 77 bytes

lambda s:''.join(map(lambda c,C:c+('f'+c*(c!=C))*(c in'aeiouAEIOU'),s,s[1:]))

Try it online!


Saved:

  • -3 bytes, thanks to ovs.
\$\endgroup\$
  • \$\begingroup\$ @ovs, Thanks :) \$\endgroup\$ – TFeld May 29 '18 at 7:57
2
\$\begingroup\$

Java 8, 68 bytes

s->s.replaceAll("([aeiou])","$1f$1").replaceAll("([aeiou])\\1","$1")

Try it online.

Or 77 bytes if we have to handle uppercase vowels as well:

s->s.replaceAll("(?i)([aeiou])","$1f$1").replaceAll("([AEIOUaeiou])\\1","$1")

Try it online.

Explanation:

s->                             // Method with String as both parameter and return-type
  s.replaceAll("([aeiou])",     //  Replace every vowel with:
               "$1f$1")         //  the vowel, 'f', the vowel appended to each other
   .replaceAll("([aeiou])\\1",  //  Then replace every duplicated vowels
               "$1")            //  to a single one
\$\endgroup\$
0
\$\begingroup\$

Prolog (SWI), 177 163 155 bytes

A+B:-append(A,B).
S-[H|T]-R:-S-T-Q,([I,[H,H],K]+Q,K-[H]-L,[I,[H,102,H,102,H],L]+R;[I,[H],K]+Q,K-[H]-L,[I,[H,102,H],L]+R;R=Q).
R-_-R.
S-R:-S-`aeiouAEIOU`-R.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Red, 81 bytes

func[s][foreach c{aoeiu}[replace/all replace/all s c rejoin[c"f"c]rejoin[c c]c]s]

Lowercase vowels only - it's much shorter now without using parse.

Try it online!

Red, 132 bytes

func[s][v: charset["aoeiuAOEIU"]parse s[any[copy n v n(prin rejoin[n"f"n"f"n])|
copy n v(prin rejoin[n"f"n])| copy n skip(prin n)]]]

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Python 2, 82 76 bytes

i=input()
for x in"aeiouAEIOU":i=i.replace(x,x+"f"+x).replace(x*2,x)
print i

Try it online!

Actually shorter to use 2 replaces rather than the split and join that was there previously.

If we are required to have "Abc" output "Afabc" instead of "AfAbc" then that costs another 8 bytes...

i=input()
for x in"aeiouAEIOU":i=i.replace(x,x+"f"+x.lower()).replace(x*2,x)
print i

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Excel, 218 bytes

Pretty blunt:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"a","afa"),"e","efe"),"i","ifi"),"o","ofo"),"u","ufu"),"aa","a"),"ee","e"),"ii","i"),"oo","o"),"uu","u")

Substitutes a, e, i, o & u with *f*. Followed by removing all duplicate vowels in turn.

\$\endgroup\$
0
\$\begingroup\$

Perl 5, 40 characters

perl -pe 's/([aeiou])\1?/$1."f\L$1"x length$&/egi'

I've waited a long time to make use of perl's \L regex feature. A long time.

\$\endgroup\$
0
\$\begingroup\$

C (gcc), 118 bytes

f(char*s){char*u="aeiou",v[4]={0};for(;*v=v[2]=*s++;)printf("%s%s%s"+!strchr(u,*v|=(*v>64)*32)*4,v+2,"f",*s-*v?v:"");}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

C# (.NET Core), 102 bytes

102 bytes

s=>string.Concat(s.Select((c,i)=>c+("aeiouAEIOU".Contains(c)?"f"+(++i<s.Length&&s[i]==c?"":c+""):"")))

Try it online!

Linq version, looking for improvement :)

132 bytes

s=>{var r="";int l=s.Length,i=0;for(;i<l;){var c=s[i];r+=c+("aeiouAEIOU".Contains(s[i++])?"f"+(i<l&&s[i]==c?"":c+""):"");}return r;}

Try it online!

flat C# solution, looking for improvement :)

\$\endgroup\$

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