j_0sh
|
  |
| Joined: 05 Mar 2015 |
| Total Posts: 512 |
|
|
| 02 Mar 2016 04:12 PM |
The goal of this code golf is to code a function/method that can count the number of vowels in any string supplied as an argument.
The rules:
Code must be as small as possible. The code must run/compile with no errors. You can use any language you like.
Let's have a fun game, then. Begin! |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Mar 2016 04:24 PM |
I'm sure you can shorten it but whatever:
function a(b)return b:gsub("[aeiou]","")end |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2016 04:27 PM |
function a(b)return b:gsub("[aeiou]","")end print(a("AaEeIIo")) --AEII 3
@cnt
|
|
|
| Report Abuse |
|
|
| |
|
darthpyro
|
  |
| Joined: 18 Aug 2009 |
| Total Posts: 3569 |
|
|
| 02 Mar 2016 04:36 PM |
| None of these segments actually count the number of vowels. ;P |
|
|
| Report Abuse |
|
|
darthpyro
|
  |
| Joined: 18 Aug 2009 |
| Total Posts: 3569 |
|
|
| 02 Mar 2016 04:38 PM |
| Wait I forgot about the second gsub param. P; |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2016 04:44 PM |
Well if you want just the number outputted:
function vowels(word) local n = 0 for l in word:gmatch('[%daeiou]') do n = n + 1 end return n end
print(vowels('The quick brown fox jumps over the lazy dog'))
--11
|
|
|
| Report Abuse |
|
|
| |
|
|
| 02 Mar 2016 04:52 PM |
a
a in Kingkillerscript is a command that counts the number of vowels in the supplied string, given as a program argument.
You said I can use any language I like. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Mar 2016 05:13 PM |
| [aeiouAEIOU] lelelyhllyltylkiotjitj |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 02 Mar 2016 05:34 PM |
cntkillme's in moonscript
a=(b)->b\gsub "[aeiouAEIOU]",""
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 02 Mar 2016 06:00 PM |
| a==>@gsub "[aeiouAEIOU]","" |
|
|
| Report Abuse |
|
|
j_0sh
|
  |
| Joined: 05 Mar 2015 |
| Total Posts: 512 |
|
| |
|
j_0sh
|
  |
| Joined: 05 Mar 2015 |
| Total Posts: 512 |
|
| |
|
Intrance
|
  |
| Joined: 04 Dec 2008 |
| Total Posts: 208 |
|
|
| 03 Mar 2016 04:59 PM |
import java.util.Scanner;
public class vowels { public static void main (String args[]) { Scanner stdin = new Scanner(System.in); String string1; string1 = stdin.nextLine(); string1 = string1.toLowerCase();
} public static int numberVowels(String string1) {
int count = 0; int vowels = 0; int consonants = 0; for (int i = 0; i < string1.length(); i++) { char ch = string1.charAt(i); if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { vowels++; } } return vowels; } } |
|
|
| Report Abuse |
|
|
Intrance
|
  |
| Joined: 04 Dec 2008 |
| Total Posts: 208 |
|
| |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 03 Mar 2016 05:22 PM |
| You missed the point of a code golf. |
|
|
| Report Abuse |
|
|
j_0sh
|
  |
| Joined: 05 Mar 2015 |
| Total Posts: 512 |
|
|
| 03 Mar 2016 05:24 PM |
| You missed the point of a code golf.[2] |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2016 07:05 PM |
| Whoever uses Java in code golf automatically loses |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
j_0sh
|
  |
| Joined: 05 Mar 2015 |
| Total Posts: 512 |
|
|
| 03 Mar 2016 07:12 PM |
| Yes, Java's design isn't good for code golf. Most OOP languages aren't, in any case. I'm not bashing Java, though. I had fun using it to make Minecraft mods. |
|
|
| Report Abuse |
|
|