13
\$\begingroup\$

This is a rather easy challenge.

Challenge

Input will contain a string (not null or empty) of maximum length 100. Output the number of vowels in each word of the string, separated by spaces.

Rules

  • The string will not be more than 100 characters in length.
  • The string will only contain alphabets A-Z , a-z and can also contain spaces.
  • Input must be consumed from the stdin or command line arguments.
  • Output must be outputted in the stdout.
  • You can write a full program, or a function that takes input from the stdin and outputs the result.
  • The vowels that your program/function needs to count are aeiou and AEIOU.

Test Cases

This is the first test case     --> 1 1 1 1 1 2
one plus two equals three       --> 2 1 1 3 2
aeiou AEIOU                     --> 5 5
psst                            --> 0
the quick brown fox jumped over the lazy dog --> 1 2 1 1 2 2 1 1 1

Scoring

This is , so the shortest submission (in bytes) wins.

\$\endgroup\$
  • 6
    \$\begingroup\$ Is there a reason why you insist on a rather restrictive I/O format? Not every language can (conveniently) interact with STDIN and STDOUT. We have defaults for this (which you are of course free to override if you wish), which also allow command-line argument, function argument, return value etc. (They can also be found in the tag wiki.) \$\endgroup\$ – Martin Ender May 21 '15 at 10:58
  • \$\begingroup\$ @MartinBüttner , "Is there a reason why you insist on a rather restrictive I/O format?" -- No. I just like stdin with stdout. I don't like to "get input" via the function arguments. command-line arguments seems ok. I've added it into the post. \$\endgroup\$ – Spikatrix May 21 '15 at 11:04
  • 4
    \$\begingroup\$ WIKIPEDIA: The name "vowel" is often used for the symbols that represent vowel sounds in a language's writing system, particularly if the language uses an alphabet. In writing systems based on the Latin alphabet, the letters A, E, I, O, U, and sometimes Y are all used to represent vowels. However, not all of these letters represent vowels in all languages. What do YOU mean by vowels? \$\endgroup\$ – edc65 May 21 '15 at 14:37
  • \$\begingroup\$ Is a single trailing space okay? \$\endgroup\$ – Alex A. May 21 '15 at 15:19
  • 3
    \$\begingroup\$ Use the Sandbox for Proposed Challenges. \$\endgroup\$ – mbomb007 May 22 '15 at 1:09

34 Answers 34

1
2
0
\$\begingroup\$

K (oK), 22 bytes

Solution:

(+/,/"aeiou"=\:)'" "\_

Try it online!

Examples:

> (+/,/"aeiou"=\:)'" "\_"This is the first test case"
1 1 1 1 1 2
> (+/,/"aeiou"=\:)'" "\_"aeiou AEIOU"
5 5

Explanation:

Interpretted right-to-left, lowercase input, split on whitespace, then check each word against each vowel, flatten and sum results:

(+/,/"aeiou"=\:)'" "\_ / the solution
                     _ / convert to lowercase
                 " "\  / split on " "
                '      / each
(              )       / do all this together
     "aeiou"=\:        / check each-left (\:) "aeiou" equal (=) to right argument
   ,/                  / flatten
 +/                    / sum
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Java 8, 137 135 bytes

As full program:

interface M{static void main(String[]a){for(String s:a[0].split(" "))System.out.print(s.replaceAll("[^aeiouAEIOU]","").length()+" ");}}

Try it here.

As function:

A full program is apparently shorter than a function in this case (137 bytes):

v->{for(String s:new java.util.Scanner(System.in).nextLine().split(" "))System.out.print(s.replaceAll("[^aeiouAEIOU]","").length()+" ");}

Try it here.

Explanation:

interface M{                       // Class
  static void main(String[]a){     //  Mandatory main-method
    for(String s:a[0].split(" "))  //   Loop over the words of the input:
      System.out.print(s.replaceAll("[^aeiouAEIOU]","")
                                   //    Remove every non-vowel,
                        .length()  //    and print the length of the remainder
                       +" ");      //    + a space
                                   //   End of loop (implicit / single-line body)
  }                                //  End of main-method
}                                  // End of class
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Perl 5, 23 bytes

19 bytes code + 4 for -p040.

$_=lc=~y/aeiou//.$"

Try it online!

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

Common Lisp, 74 bytes

(loop as i =(read)do(print(count-if(lambda(x)(find x"AEIOU"))(string i))))

Try it online!

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

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.