20
\$\begingroup\$

Given a word, your task is to compact it by saving its first character and removing any other vowel (aeiou).

Input

Your input can be the word in STDIN, a function argument or any other input format that doesn't break the standard loopholes. You can assume the input only consists of lower characters.

Output

Your output must be the word, compacted.

Examples

i -> i
ate -> at
potato -> ptt
ksboejqfgcrauxpwivtzndlhmy -> ksbjqfgcrxpwvtzndlhmy

Score

This is a code-golf, so shortest answer in bytes wins, good luck!

\$\endgroup\$

37 Answers 37

7
\$\begingroup\$

05AB1E, 6 bytes

ćsžMм«

Try it online!

Explanation

       Input (e.g.). potato
ć      Head extract. otato, p
 s     Swap        . p, otato
  žM   Vowels      . p, otato, aeiou
    м  Remove      . p, tt
     « Concatenate . ptt

Implicit output    .
\$\endgroup\$
5
\$\begingroup\$

Retina, 15 13 8 bytes

0T1,`v`_

Transliterates lowercase vowels into nothing (_) in the 0th in 0-indexing match of the implicit regex that matches the entire string, after index 1 (1,).

Try it online!

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

C (gcc), 57 56 52 bytes

Time to roll out some magic numbers!

Thanks @Arnauld for even better magic numbers!

f(char*a,char*b){for(*b++=*a;*b=*++a;)b+=4373%*a&1;}

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ so those magic numbers check if something is a vowel? \$\endgroup\$ Apr 12, 2020 at 14:26
  • \$\begingroup\$ [repost] Yes. I found that by enumerating those constants. \$\endgroup\$
    – newbie
    Apr 12, 2020 at 14:33
  • 1
    \$\begingroup\$ 52 bytes \$\endgroup\$
    – Arnauld
    Apr 12, 2020 at 15:01
  • \$\begingroup\$ Thanks! Very nice. @Arnauld \$\endgroup\$
    – newbie
    Apr 12, 2020 at 15:03
4
\$\begingroup\$

J, 15 bytes

{.,'aeiou'-.~}.

Try it online!

Straightforward:

  • {. head...
  • , catted with...
  • 'aeiou'-.~ vowels, set minused from...
  • }. tail
\$\endgroup\$
4
\$\begingroup\$

sed, 14 bytes

s/\B[aeiou]//g

Try it online!


Bash + Core utilities, 19 bytes

sed s/\\B[aeiou]//g

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ sed solution is nice. \$\endgroup\$
    – Jonah
    Apr 12, 2020 at 15:20
4
\$\begingroup\$

Python 2, 43 bytes

Another 43-byte solution in Python.

lambda s:s[0]+s[1:].translate(None,'aeiou')

Try it online!

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

Ruby, 31 bytes

->x{x[0]+x[1..].tr('aeiou','')}

Needs to be run on Ruby 2.6 or above, since it uses an endless range.

(TIO is on 2.5.5, so it doesn't work there.)

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

Excel, 87 bytes

=LET(q,SEQUENCE(LEN(A1)),x,MID(A1,q,1),CONCAT(IF(ISERROR(FIND(x,"aeiou"))+(q=1),x,"")))

Hopefully this link works. Try it here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Is there an online Excel simulator to run this? My own (outdated) Excel version doesn't seem to have functions like LET or SEQUENCE.... \$\endgroup\$ Mar 27, 2021 at 18:24
  • 1
    \$\begingroup\$ Added link. Hopefully, it works. \$\endgroup\$
    – Axuary
    Mar 27, 2021 at 18:34
3
\$\begingroup\$

Python 3, 44 43 bytes

lambda a,*s:[a]+[c[c in"aeiou":]for c in s]

Try it online!

Input: Characters of the word. E.g f("a", "t", "e")
Output: A list of characters.

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

Jelly, 6 bytes

Ḣ;ḟØẹ$

Try it online!

How?

Ḣ;ḟØẹ$ - Link: list of characters, W
Ḣ      - head & yield
     $ - last two links as a monad - i.e. f(rest of W)
  ḟ    -   filter discard:
   Øẹ  -     lower-case vowels
 ;     - (head of W) concatenate (f(rest of W))
\$\endgroup\$
2
  • \$\begingroup\$ I just arrived at the exact same solution before noticing this one. I think the one thing worth mentioning in the explanation is that mutates the input \$\endgroup\$ May 17, 2020 at 5:26
  • 1
    \$\begingroup\$ Yep - "head & yield" and "rest of W". \$\endgroup\$ May 17, 2020 at 15:22
3
\$\begingroup\$

naz, 102 bytes

2x1v2a6m8m1a2x2v4a2x3v4a2x4v6a2x5v6a2x6v1x1f1r3x1v2e3x2v1e3x3v1e3x4v1e3x5v1e3x6v1e1o1f0x1x2f0a0x1r1o1f

Works for any null-terminated input string.

Try it online!

Explanation (with 0x instructions removed)

2x1v                                           # Set variable 1 equal to 0
2a6m8m1a2x2v                                   # Set variable 2 equal to 97 ("a")
4a2x3v                                         # Set variable 3 equal to 101 ("e")
4a2x4v                                         # Set variable 4 equal to 105 ("i")
6a2x5v                                         # Set variable 5 equal to 111 ("o")
6a2x6v                                         # Set variable 6 equal to 117 ("u")
1x1f                                           # Function 1
    1r                                         # Read a byte of input
      3x1v2e                                   # Goto function 2 if it equals variable 1
            3x2v1e3x3v1e3x4v1e3x5v1e3x6v1e     # Jump back to the start of the function
                                               # if it equals variable 2, 3, 4, 5, or 6
                                          1o1f # Otherwise, output it, then call the
                                               # function again
1x2f                                           # Function 2
    0a                                         # Add 0 to the register
1r1o                                           # Output the first byte of input
1f                                             # Call function 1
\$\endgroup\$
2
\$\begingroup\$

Erlang (escript), 26 bytes

f([H|T])->[H]++T--"aeiou".

Try it online!

Explanation

f([H|T])->       % Match the head & tail of the input string.
[H]              % Wrap the head in a list,
   ++T           % Append the tail
      --"aeiou". % with all vowels removed.
\$\endgroup\$
2
\$\begingroup\$

APL (Dyalog), 14 bytes

⊃,'aieou'~⍨1∘↓

Try it online!

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

Haskell, 34 bytes

f(a:s)=a:[x|x<-s,notElem x"aeiou"]

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can do all(/=x) for notElem x. \$\endgroup\$
    – xnor
    Apr 13, 2020 at 21:26
2
\$\begingroup\$

Perl 5 -p, 18 bytes

s/(?<!^)[aeiou]//g

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Hey, came up with prety much the same! You can remove < from the lookbehind for one, or if you use the regex as the arg to -F you can have a 5 byte solution: Try it online! \$\endgroup\$ May 1, 2020 at 9:09
2
\$\begingroup\$

APL (NARS2000 0.5.13.0), 20 unicode char (so 20 byte or 40 byte?)

(↑,((~∘'aeiou')1∘↓))


Sample output:

      (↑,((~∘'aeiou')1∘↓)) 'i'
i
      (↑,((~∘'aeiou')1∘↓)) 'ate'
at
      (↑,((~∘'aeiou')1∘↓)) 'potato'
ptt
      (↑,((~∘'aeiou')1∘↓)) 'ksboejqfgcrauxpwivtzndlhmy' 
ksbjqfgcrxpwvtzndlhmy
      (↑,((~∘'aeiou')1∘↓)) ''


Thanks to the tacit feature added lately.

Since APL code chars are unicode chars, I am not sure if one char should be counted as two byte or not.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think those are 28 UTF8-bytes. \$\endgroup\$ May 18, 2020 at 23:53
2
\$\begingroup\$

PHP, 41 bytes

<?=preg_replace("/\\B[aeiou]/","",$argn);

Try it online!

I wanted to find an original solution but it ends up like everyone's regex.. Deception is my middle name

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

PowerShell, 33 30 bytes

-3 bytes thanks to @CommandMaster

$args-split"(.)[aeiou]"-join''

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ never used powershell, but $args-split"(.)[aeiou]"-join'' seems to work for -3 \$\endgroup\$ Apr 23, 2020 at 15:22
  • \$\begingroup\$ @CommandMaster wow, wouldn't expect that to work, thank you ;) \$\endgroup\$
    – Elgirhath
    Apr 23, 2020 at 15:27
  • \$\begingroup\$ ? Try it online! \$\endgroup\$
    – mazzy
    Apr 24, 2020 at 4:57
  • 1
    \$\begingroup\$ @mazzy 24 bytes: $args-replace'\B[aeiou]' \$\endgroup\$ Apr 24, 2020 at 5:22
2
\$\begingroup\$

Brachylog, 7 bytes

h|b;Ḅ∋ᵛ

Try it online!

Generator.

 |         The output is
h          the first element of the input,
 |         or
     ∋ᵛ    some shared element of
 |b        the input without its first element
   ;Ḅ      and the lowercase consonants.
\$\endgroup\$
2
\$\begingroup\$

Factor, 31 bytes

[ 1 cut "aeiou"without append ]

Try it online!

Explanation

It's a quotation (anonymous function) that takes one string as input and leaves one string as output. Assuming "potato" is on top of the data stack when this quotation is called...

  • 1 Push one to the data stack. Stack: "potato" 1
  • cut Cut a sequence into two pieces at a given index. Stack: "p" "otato"
  • "aeiou" Push a string to the data stack. Stack: "p" "otato" "aeiou"
  • without Remove elements from NOS (next on stack) that are in TOS (top of stack). Stack: "p" "tt"
  • append Concatenate two strings. Stack: "ptt"
\$\endgroup\$
1
\$\begingroup\$

Red, 33 bytes

func[s][trim/with next s"aeiou"s]

Try it online!

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

K (oK), 20 bytes

{(*x),(1_x)^"aoeiu"}

Try it online!

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

Python 3, 61 bytes

lambda s:s[0]+''.join(filter(lambda x:x not in'aeiou',s[1:]))

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to the site. This repeats the first character if it is a consonant. You should change the s to s[1:] to prevent this. \$\endgroup\$
    – Wheat Wizard
    Apr 12, 2020 at 19:09
  • \$\begingroup\$ @AdHocGarfHunter Thank you! :) \$\endgroup\$ Apr 12, 2020 at 19:12
1
\$\begingroup\$

Python 3, 57 55 bytes

Saved 2 bytes thanks to ovs!!!

lambda s:s[0]+''.join(c for c in s[1:]if{c}-{*'aeiou'})

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ if c not in'aeiou' can be 2 bytes shorter with set difference: if{c}-{*'aeiou'} \$\endgroup\$
    – ovs
    Apr 12, 2020 at 18:41
  • \$\begingroup\$ @ovs That's clever - thanks! :-) \$\endgroup\$
    – Noodle9
    Apr 12, 2020 at 19:24
1
\$\begingroup\$

Charcoal, 12 bytes

ΦS¬∧κ№aeiouι

Try it online! Link is to verbose version of code. Explanation:

 S              Input string
Φ ¬             Exclude characters where
     №aeiouι    Character is a vowel
   ∧κ           And index is not zero
                Implicitly print
\$\endgroup\$
1
\$\begingroup\$

JavaScript (ES6),  27  26 bytes

Saved 1 byte thanks to @Neil

Returns a list of characters.

s=>s.match(/^.|[^aeiou]/g)

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Why not use ^ instead of \b? \$\endgroup\$
    – Neil
    Apr 12, 2020 at 21:58
  • \$\begingroup\$ @Neil I saw your comment a while ago and forgot about it. Thanks! \$\endgroup\$
    – Arnauld
    Apr 13, 2020 at 22:34
  • \$\begingroup\$ Is this valid? An array of characters isn't the same thing as a string, in JavaScript. \$\endgroup\$ May 1, 2020 at 9:57
1
\$\begingroup\$

Keg -ir, 34 16 bytes

Huge saving thanks to Lyxal.

,(:⅍`aeiou`-[,|_

Try it online!

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

Pyth, 12 bytes

+hQ-tQ"aeiou

Explanation

+hQ-tQ"aeiou
    tQ        : Everything except first element of evaluated input
   -  "aeiou  : Remove all occurrences of a, e, i, o and u from the string
+hQ           : Prepend first element of evaluated input

Try it online!

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

Ruby -p, 22 19 bytes

gsub /\B[aeiou]/,''

Try it online!

Thanks to Command Master for -3 bytes.

\$\endgroup\$
1
  • \$\begingroup\$ 19 chars: gsub /\B[aeiou]/,'' \$\endgroup\$ May 18, 2020 at 8:16
1
\$\begingroup\$

JavaScript (V8), 42 bytes

s=>s[0]+s.substr(1).replace(/[aeiou]/g,'')

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Replace substr with slice to save 1 byte \$\endgroup\$
    – RezNesX
    Nov 16, 2020 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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