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

30 Answers 30

6
\$\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    .
```
| improve this answer | |
\$\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!

| improve this answer | |
\$\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!

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

J, 15 bytes

{.,'aeiou'-.~}.

Try it online!

Straightforward:

  • {. head...
  • , catted with...
  • 'aeiou'-.~ vowels, set minused from...
  • }. tail
| improve this answer | |
\$\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!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ sed solution is nice. \$\endgroup\$ – Jonah Apr 12 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!

| improve this answer | |
\$\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.)

| improve this answer | |
\$\endgroup\$
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.

| improve this answer | |
\$\endgroup\$
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))
| improve this answer | |
\$\endgroup\$
  • \$\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\$ – Unrelated String May 17 at 5:26
  • 1
    \$\begingroup\$ Yep - "head & yield" and "rest of W". \$\endgroup\$ – Jonathan Allan May 17 at 15:22
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.
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

APL (Dyalog), 14 bytes

⊃,'aieou'~⍨1∘↓

Try it online!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Haskell, 34 bytes

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

Try it online!

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

naz, 102 bytes

2a2x1v6m8m1a2x2v4a2x3v4a2x4v6a2x5v6a2x6v1x1f1r3x1v2e3x2v1e3x3v1e3x4v1e3x5v1e3x6v1e1o1f0x1x2f0a0x1r1o1f

Works for any input file terminated with the control character STX (U+0002).

Explanation (with 0x commands removed)

2a2x1v                                         # Set variable 1 equal to 2
6m8m1a2x2v                                     # 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                                   # Jump to 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 jump
1x2f                                           # Function 2
    0a                                         # Add 0 to the register
1r1o                                           # Read the first byte of input and output it
1f                                             # Call function 1
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Perl 5 -p, 18 bytes

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

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\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\$ – Dom Hastings May 1 at 9:09
2
\$\begingroup\$

PowerShell, 33 30 bytes

-3 bytes thanks to @CommandMaster

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

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ never used powershell, but $args-split"(.)[aeiou]"-join'' seems to work for -3 \$\endgroup\$ – Command Master Apr 23 at 15:22
  • \$\begingroup\$ @CommandMaster wow, wouldn't expect that to work, thank you ;) \$\endgroup\$ – Elgirhath Apr 23 at 15:27
  • \$\begingroup\$ ? Try it online! \$\endgroup\$ – mazzy Apr 24 at 4:57
  • 1
    \$\begingroup\$ @mazzy 24 bytes: $args-replace'\B[aeiou]' \$\endgroup\$ – Command Master Apr 24 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.
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Red, 33 bytes

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

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

K (oK), 20 bytes

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

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Python 3, 61 bytes

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

Try it online!

| improve this answer | |
\$\endgroup\$
  • 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\$ – Ad Hoc Garf Hunter Apr 12 at 19:09
  • \$\begingroup\$ @AdHocGarfHunter Thank you! :) \$\endgroup\$ – Param Siddharth Apr 12 at 19:12
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
| improve this answer | |
\$\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!

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

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I think those are 28 UTF8-bytes. \$\endgroup\$ – Jonathan Frech May 18 at 23:53
1
\$\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

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Keg -ir, 34 16 bytes

Huge saving thanks to Lyxal.

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

Try it online!

| improve this answer | |
\$\endgroup\$
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!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Ruby -p, 22 19 bytes

gsub /\B[aeiou]/,''

Try it online!

Thanks to Command Master for -3 bytes.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 19 chars: gsub /\B[aeiou]/,'' \$\endgroup\$ – Command Master May 18 at 8:16
1
\$\begingroup\$

JavaScript (V8), 42 bytes

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

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 66 bytes

 INPUT LEN(1) . F REM . I
V I ANY('aeiou') =:S(V)
 OUTPUT =F I
END

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\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!

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

CJam, 15 bytes

l_0=\1>"aeiou"-

Try it online!

It's 15 bytes because there is no better way to push all those vowels.

Explained

l_0=\1>"aeiou"-
l_                  e# Take the input and duplicate it: [input, input]
  0=                e# From the input, take the first character: [input, input[0]]
    \               e# Swap the top two items: [input[0], input]
     1>             e# Drop the first character: [input[0], input[1:]]
       "aeiou"      e# Push the string "aeiou": [input[0], input[1:], "aeiou"]
              -     e# Remove all occurances of the above string from the input[1:] and print.
| improve this answer | |
\$\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.