[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
QUICK WRITE A PROGRAM IN YOUR FAVORITE LANGUAGE THAT COUNTS
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 26
File: 1467318962646.jpg (29 KB, 412x430) Image search: [Google]
1467318962646.jpg
29 KB, 412x430
QUICK

WRITE A PROGRAM IN YOUR FAVORITE LANGUAGE THAT COUNTS ALL THE VOWELS FROM THE USER INPUT

OR THIS BIRD IS GONNA STAB YOU
>>
inb4 homework

It's not homework you mongoloids.
Last thread: >>55357763

#include <stdio.h>
#include <stdlib.h>

int isvowel(char c) {
switch(c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
return 1;
default:
return 0;
}

return 0;
}

int main(int argc, char** argv) {
char c;
int vowels = 0;

while(1) {
c = getchar();
if(c == EOF) {
break;
}
vowels += isvowel(c);
}
printf("Vowels: %d\n", vowels);

return EXIT_SUCCESS;
}
>>
#include <stdio.h>
#include <stdlib.h>

int isvowel(char c) {
switch(c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
return 1;
default:
return 0;
}

return 0;
}

int main(int argc, char** argv) {
char c;
int vowels = 0;

while(1) {
c = getchar();
if(c == EOF) {
break;
}
vowels += isvowel(c);
}
printf("Vowels: %d\n", vowels);

return EXIT_SUCCESS;
}

//ok?
>>
vowels = ["a", "e", "i", "o", "u"]

user_input = input("Enter phrase: ")

result = 0

for i in list(user_input):
if i in vowels:
result += 1

print(result)
>>
>>55375709
fuck

vowels = ["a", "e", "i", "o", "u"]

user_input = input("Enter phrase: ")

user_input = user_input.lower()

result = 0

for i in list(user_input):
if i in vowels:
result += 1

print(result)
>>
>>55375654
>homework
>>
>>55375709
>>55375736
Doesn't work with Chinese.
>>
<?php
$vowels = array('a','e','i','o','u',A','E','I','O','U');
$user_input = $_POST['input'];
$result = 0;

for ($i = 0; $i < strlen($user_input); $i++) {
for($j = 0; $j < 10; $j++){
if($user_input[i] == $vowels[j])
$result+=1;
}
}
echo $result;
?>


:^)
>>
File: 1467471847306.jpg (23 KB, 408x426) Image search: [Google]
1467471847306.jpg
23 KB, 408x426
GET TO WORK YOU FUCKING PLEBS
>>
>>55375654
gets.scan(/aeiou/i).size

you big fgt OP
>>
Use regex to filter out all the non-vowels and then get the size of the string.
>>
 file=$1
v=0
if [ $# -ne 1 ]
then
echo "$0 fileName"
exit 1
fi
if [ ! -f $file ]
then
echo "$file not a file"
exit 2
fi
# read vowels
exec 3<&0
while read -n 1 c
do
l="$(echo $c | tr '[A-Z]' '[a-z]')"
[ "$l" == "a" -o "$l" == "e" -o "$l" == "i" -o "$l" == "o" -o "$l" == "u" ] && (( v++ )) || :
done < $file
echo "Vowels : $v"
echo "Characters : $(cat $file | wc -c)"
echo "Blank lines : $(grep -c '^$' $file)"
echo "Lines : $(cat $file|wc -l )"

>>
int countVowers(std::string str)
{
int count = 0;
std::string dict = "aeiou";
std::string::iterator str_it = str.begin();
std::string::iterator dict_it;
for (std::string::iterator str_it = str.begin(); str_it != str.end(); str_it++)
for (std::string::iterator dict_it = dict.begin(); dict_it != dict.end(); dict_it++)
if (*str_it == *dict_it)
count++;
return count;
}
>>
>>55376263
fix
int countVowers(std::string str)
{
int count = 0;
std::string dict = "aeiou";
for (std::string::iterator str_it = str.begin(); str_it != str.end(); str_it++)
for (std::string::iterator dict_it = dict.begin(); dict_it != dict.end(); dict_it++)
if (*str_it == *dict_it)
count++;
return count;
}
>>
>>55376273
do you enjoy typing std:: all the time?
>>
>>55376273
I forgot some lines
int countVowers(std::string str)
{
int count = 0;
std::string dict = "aeiou";
for (std::string::iterator str_it = str.begin(); str_it != str.end(); str_it++)
*str_it = tolower(*str_it);
for (std::string::iterator str_it = str.begin(); str_it != str.end(); str_it++)
for (std::string::iterator dict_it = dict.begin(); dict_it != dict.end(); dict_it++)
if (*str_it == *dict_it)
count++;
return count;
}
>>
>>55376321
yep
>>
>>55375654
t = 0
for c in input():
if c.lower() in 'aeiou':
t += 1
print(t)
>>
>>55376322
Hmm. I fixed it again
int countVowers(std::string str)
{
int count = 0;
std::string dict = "aeiou";
for (std::string::iterator str_it = str.begin(); str_it != str.end(); str_it++)
for (std::string::iterator dict_it = dict.begin(); dict_it != dict.end(); dict_it++)
if (tolower(*str_it) == *dict_it)
count++;
return count;
}
>>
>>55375663
Why not use toLower and decrease the switch cases?
>>
File: 1447264064114.png (14 KB, 1372x326) Image search: [Google]
1447264064114.png
14 KB, 1372x326
>>55375654
Am i cool yet senpai?
>>
>>55376344
print(len([c for c in input() if c in 'aeiouAEIOU']))
>>
gets.scan(/[aeiou]/).count
>>
>>55376594
Uppercase?
>>
>>55376606
Gets.downcase.scan(/[aeiou]/).size
>>
>coding in anything lower level than ruby or python and taking 5-15x the lines
I just can't anymore, Ruby is too good
>>
IFS='AEIOUaeiou'; read fag; for dick in $fag; do echo "aids"; done | wc | awk '{print $1}'


Did I do well? Complement me, please!
>>
local text = {}
amo = 0


print("Enter phrase: ")
local input = tostring(io.read())

input:gsub(".",function(c) table.insert(text,c) end)

for i = 1, #text do

if text[i] == string.char(97, 101, 105, 111, 117, 121) then
amo = amo + 1
end

end

print(table.concat(text).." contains "..amo.." vowel(s).")


I fucked this up. How?
>>
Download some examples.

py example.py
>>
>>55375654
#include <iostream>

using namespace std;

int main() {
string input;
cout << "Type in some string:" >> endl;
cin >> input;
int vowels;

for (int i=0;i<input.length;i++)
{
if (input[i]=='B' || input[i]=='C' || input[i]=='D' || input[i]=='F' || input[i]=='G' || input[i]=='H' || input[i]=='J' || input[i]=='K' || input[i]=='L' || input[i]=='M' || input[i]=='N' || input[i]=='P' || input[i]=='Q' || input[i]=='R' || input[i]=='S' || input[i]=='T' || input[i]=='V' || input[i]=='W' || input[i]=='X' || input[i]=='Y' || input[i]=='Z' || input[i]=='b' || input[i]=='c' || input[i]=='d' || input[i]=='f' || input[i]=='g' || input[i]=='h' || input[i]=='j' || input[i]=='k' || input[i]=='l' || input[i]=='m' || input[i]=='n' || input[i]=='p' || input[i]=='q' || input[i]=='r' || input[i]=='s' || input[i]=='t' || input[i]=='v' || input[i]=='w' || input[i]=='x' || input[i]=='y' || input[i]=='z')
{
// this is not a vowel
}
else
{
vowels = vowels + 1;
}

cout << "There are " << vowels << " vowels in this sentence";
}
}
>>
>>55376816
what the fuck
>>
>>55376811
>IFS='AEIOUaeiou'; read fag; for dick in d$fag; do echo "aids"; done | wc | awk '{print $1}'

Fixed an edge case: notice the d.
>>
>>55376497
Technically a bit longer runtime, but it doesn't really matter.
>>
Haven't actually tested but this should be right.

int main(int argc, char** argv[]) {
std::set<char> vowels = {'a', 'e', 'i', 'o', 'u'};

std::string input = std::string(argv[0]);

int count = 0;
for (char& c : input) {
if (vowels.count(c) > 0)
count++;
}

std::cout << "Vowels: " << count << "\n";

return 0;
}
>>
local count = 0

for vowel in (arg[1] or io.input():read()):gmatch("[aeiouAEIOU]") do
count = count + 1
end

print(count)


It reads from the command line or prompts the user if not available BEAT THAT
>>
npm install vowel-counter


I love JavaScript
>>
This is totally unchecked, I'm on my phone. Let's see how good my mental linter is.

import functools
res = input("enter a phrase.")
vowels = set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'])
print(functools.filter(lambda x: x in vowels, res.split("")).len())

Can somebody test this for me?
>>
>>55376869
What?
>>
>>55377066
fuck I used len wrong, shm thbq fma
>>
>>55376497
It'd be slower and consume more memory.
>>
vowels=0
for c in list(input()):
if c in 'aeiouAEIOU':
vowels += 1
print(vowels)
# pls no stabs bird
>>
print(len([x for x in input().lower() if x in 'aeiou']))

python wins again
>>
>>55375654
input.toCharList.foldLeft(0)( (acc, c ) => if vowels.contains(c) acc + 1 else acc )
>>
Console.WriteLine(Console.ReadLine().Count(chr => "aeiou".Contains(char.ToLowerInvariant(chr))));
>>
def stabbing_bird(input)
return input.downcase.count "aiueo"
end
stabbing_bird(gets.chomp)


Am I doing this right? Don't stab me please.
>>
Damn, code took longer than expected. It is mostly generating all vovel list though

++++++++++[->++++++>++++++>>+++++++>+++++++>>
+++++++>+++++++>>++++++++>++++++++>>++++++++>
++++++++>>++++++++++>++++++++++>>++++++++++>+
+++++++++>>++++++++++>++++++++++>>+++++++++++
>+++++++++++>>++++++++++++>++++++++++++<<<<<<
<<<<<<<<<<<<<<<<<<<<<<<]+>+++++>+++++>+>->->+
>+++>+++>+>->->+>+++++>+++++>+>--->--->+>+>+>
+>+++++>+++++>+>+>+>+>--->--->>,[[->+>+<<]+++
+++++++>>>>-<<<<[->[-<<[<<<]<->>>>[>>>]<<<<]>
[-<+>>+<]>[-<+>]<<<<[<<<]+<<<->>>[>>>]<<<<<]<
[<[[-]->+[->+]->+<<+[-<+]]<<]+>[[->+>+<<]>>-[
-<<+>>]+>]<->>[-]>[-]>>+>---------[[+]>+<]>>+
<<<<<<<,]>>>>>>[->-<]>>++++++++++<[->-[>+>>]>
[+[-<+>]>+>>]<<<<<]>>>[>++++++++[-<++++++>]<.
[-]]++++++++[-<++++++>]<.
>>
>>55377058
You forgot to --save. Now I cannot run your code.
>>
>>55376538
C# w/o LINQ is shit, you should learn it. >>55377519
>>
>>55377566
what the fuck is this?
>>
>>55377617
brainfuck
>>
>>55377566
holy shit it actually works
>>
>>55377659
of course it does
>>
>>55377566
Further optimized the code size

>->++++++++++[->++++++>>>+++++++>>>+++++++>>>
++++++++>>>++++++++>>>++++++++++>>>++++++++++
>>>++++++++++>>>+++++++++++>>>+++++++++++++[-
<+]->]<+>>+++++>>>->>>+++>>>->>>+++++>>>--->>
>+>>>+++++>>>+>>>---[[-<+<+>>]+<<<]+[>>>]<<<-
>,[[->+>+<<]++++++++++>>>>-<<<<[->[-<<[<<<]<-
>>>>[>>>]<<<<]>[-<+>>+<]>[-<+>]<<<<[<<<]+<<<-
>>>[>>>]<<<<<]<[<[[-]->+[->+]->+<<+[-<+]]<<]+
>[[->+>+<<]>>-[-<<+>>]+>]<->>[-]>[-]>>+>-----
----[[+]>+<]>>+<<<<<<<,]>>>>>>[->-<]>>+++++++
+++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>>>[>++++++
++[-<++++++>]<.[-]]++++++++[-<++++++>]<.
>>
>>55375654
(defun vowel-p (char)
(memberp (char-downcase char) '(#\a #\e #\i #\o #\u)))
(defun count-vowels (string)
(length (remove-if-not #'vowel-p string)))
>>
>>55377782
>brainfuck is shorter than some examples itt
Good job /g/
>>
Yeah yeah, I know, it's PHP. Whatever. Also not positive if the regex is correct.

echo(strlen(preg_replace('/[^AEIOU]/gi', '', $input)));
>>
>>55375654
import java.util.Scanner;

public class oopIsAFaggot {
public static void main(String[] args) {
System.out.println("Enter 3 numbaz for I cap yo ass cuzz");
Scanner s = new Scanner(System.in);
Integer one = s.nextInt(), two = s.nextInt(), three = s.nextInt();
s.close();
System.out.println(one >= two && one >= three ? one : two >= one && two >= three ? two : three);
>>
>>55378721
Wrong thread bro.
>>
>>55378721
>oopIsAFaggot
>oop
>clarely not enough OOP project
>no faggot object
>no interface faggot
you fucked up
>>
>>55375654
opSucksCocks = function(inString){
vowels = c("a","e","i","o","u")
stringLength = nchar(inString)
vowelCount = 0
for (i in 1:stringLength){
testChar = substr(inString,i,i)
vowelCount = vowelCount + is.element(testChar,vowels)
}
return(vowelCount)
}
>>
>>55375654
alert(prompt("Enter some text").replace(/[^aeiou]/gi, "").length)
>>
>>55375654
Java (still a shit language):
import java.util.*;

class Shit {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter word: ");
String input = s.nextLine().toLowerCase();
int count = 0;
for (int i=0; i<input.length(); i++) {
if ("aeiou".indexOf(input.charAt(i))>=0) {
count++;
}
}

System.out.println("Number of Vowels: "+count);
}
}
>>
>>55375709
vowels = list("aeiou")

user_input = raw_input("Enter phrase: ")

result = 0

for i in list(user_input):
if i in vowels:
result += 1

print(result)


>>55376344
> if c.lower() in 'aeiou':
Wouldn't "ae", "aei", etc. count as vowels?
>>
>>55379042
no
it reads every character, one by one
>>
>>55375654
not a single example with regex, this is why curry niggers are taking our jobs...
>>
Looking at some of the posts, I seriously hope you guys don't work on real software projects.
>>
var vowels = ['a','e','i','o','u'];
var phrase = "suck my diiiiick!";

var vowelcounter = function(phrase) {
if(phrase === "") {
return 0;
}
if(vowels.includes(phrase[0])) {
return 1 + vowelcounter(phrase.substring(1, phrase.length));
} else {
return 0 + vowelcounter(phrase.substring(1, phrase.length));
}
}

var benis = vowelcounter(phrase)
console.log(benis)


man, I miss haskell ;_;
>>
>>55379143
but bro i wrote my solution in c

that means i'm just like kernel developers and not a smelly pajeet who uses dumb languages like java
>>
Oh boy this thread again.
>>
>>55379244
read the op nerd
>>
DIM s$, vowels$, i%, c%

vowels$ = "AEIOUaeiou"

INPUT "Enter string: ", s$

FOR i% = 1 TO LEN(s$)
IF INSTR(vowels$, MID$(s$, i%, 1)) > 0 THEN
c% = c% + 1
END IF
NEXT i%

PRINT "vowel count: "; c%
>>
>>55379143
Just for you.
using System;
using System.Text.RegularExpressions;
using static System.Console;

public class Test
{
public static void Main()
{
WriteLine(Regex.Replace(ReadLine(),@"[^aeiou]","").Length);
}
}
>>
>>55375654
One liner
class Shit
{
public static void Main()
{
Console.WriteLine(Console.ReadLine().ToLower().Count(x=>x=='a'||x=='e'||x=='i'||x=='o'||x=='u'));
}
}
>>
>>55379352
Lil fix.
using System;
using System.Text.RegularExpressions;
using static System.Console;

public class Test
{
public static void Main()
{
WriteLine(Regex.Replace(ReadLine(),@"[^aeiou]","",RegexOptions.IgnoreCase).Length);
}
}
>>
>>55379143
>regex for simple count
This is why your program takes 20 seconds, when mine takes 20 nanoseconds.
>>
>>55376025
$_POST should be $_GET since you don't have the front end here.
>>
print(sum(1 for c in input() if c in ['a','e','i','o','u']))
>>
File: Stoppostingthesethreadsanytime.png (66 KB, 1378x281) Image search: [Google]
Stoppostingthesethreadsanytime.png
66 KB, 1378x281
>>55379244
>>55379257
Sorry I could care less.
>>
>>55379143
Regular expression doesn't make a difference:
import re#eeeeeeeeeeeeeeee
opIsShit = re.compile('[aeiou]')
shit_taste = input("Enter word: ").lower()
print("Number of Vowels:",len(opIsShit.findall(shit_taste)))
>>
>>55379490
>capital vowels aren't vowels
>>
kek, nice job getting /g/ to finish your highschool homework
>>
>>55379578
doh you got me! it can only count up to five vowels too!
>>
>>55376339
You may have one
>>
>>55376863
>vowels = vowels + 1

You're the worst type of person.
>>
>>55377782
I was wondering if someone would do it. Good job!
>>
>>55379427
mong
>>
>>55379490
dude u r so mad
>>
File: 1463537117616.png (952 KB, 601x888) Image search: [Google]
1463537117616.png
952 KB, 601x888
Nigga PLEASE
main = getLine >>= putStrLn . show . length . filter (`elem` "aeiouAEIOU")
>>
File: 1466195817796-fit.jpg (23 KB, 429x375) Image search: [Google]
1466195817796-fit.jpg
23 KB, 429x375
>Mfw reading these as I can only understand python
>>
var countVowels = function(str) {
return ( str.match(/[aeiou]/gi) || [] ).length;
}
>>
Really niggers ??
<file grep -io "[aeiou]"|wc -l
>>
>>55379490
m8 this is so slow
>>
>>55379885
Doesn't return value
>>55379873
Breaks if uppercase
>>55379795
Just deletes the values, doesnt return shit
>>55379490
A retard that can't inti his mother tounge's grammar
>>
>>55379885
>>55379932
>I can't run a bash screen

topkek m8
>>
>>55379490
>Cuck CUck CUCk KEKKKK CUkk XDD XDD KEK

>>>/pol/
>>
>>55379932
> I don't now what the "i" does in a regexp
>>
>>55379932
>>>55379885 (You)
>Doesn't return value
I'm sorry dear but you are stupid
>>
>>55376863
Dat if statement. I hope no one has to read your code.
>>
>>55379932
>Just deletes the values, doesnt return shit
Nigga it counts the vowels from user input and prints it back out.
countVowels :: String -> Int
countVowels = length . filter (`elem` "aeiouAEIOU") -- "returns shit"

main = getLine >>= putStrLn . countVowels
>>
This thread scares me.
You guys are terrible at coding
>>
File: obfu.png (17 KB, 842x575) Image search: [Google]
obfu.png
17 KB, 842x575
No Perl solution, I mean come on :
eval unpack u=>q{_=VAI;&4H/#XI>R1);$DQ;S`],#MF;W)E86-H*'-P;&ET+R\I>R1);$DQ;S`K*VEF*"];865I;W5=+VDI?7!R/:6YT(B1);$DQ;S!<;B)]}
>>
using System;

public class a {
static void Main() {
var inp = Console.ReadLine().ToCharArray();
char[] vo = { 'a', 'e', 'i', 'o', 'u' };
int c = 0;
for (int x = 0;x < inp.Length;x++) {
if (Array.Exists(vo, t => t == inp[x]))
c++;
}
Console.WriteLine(c);
}
}
>>
File: 1448142344323-0-b.jpg (13 KB, 214x236) Image search: [Google]
1448142344323-0-b.jpg
13 KB, 214x236
>>55379932
>Mfw I dont know how to code, I just replied to some posters saying random shit to get some (you)s

Im from /v/ :^)
>>
>>55380006
Then show us your solution, smartass.
>>
>>55380026
>I'm going to pretend that I did it on purpose so they won't laugh at me.
>>
>>55379932
https://jsfiddle.net/p6ev92ct/
>>
>>55380016
using System;

public class a {
static void Main() {
var inp = Console.ReadLine().ToLower().ToCharArray();
char[] vo = { 'a', 'e', 'i', 'o', 'u' };
int c = 0;
for (int x = 0;x < inp.Length;x++) {
if (Array.Exists(vo, t => t == inp[x]))
c++;
}
Console.WriteLine(c);
}
}
>>
>>55380026
Now that im chilled down, this was probably his intent, seeing how bad he failed three times. No way he was srs.

Ya'll niggas got memed
>>
>>55380006
It's satire.
>>
>>55380012

is this perl6 yet?
>>
>>55380041
mine is there : >>55379885

but nice 20 buggy lines of Java
>>
>>55375654
C++14:

#include <algorithm>
#include <cstring>
#include <string>

int count(const std::string &s)
{
return std::accumulate(begin(s), end(s), 0, [](auto i, auto c) { return i + (strchr("aeiouAEIOU", c) != nullptr); });
}

int main()
{
return count("This is a test");
}
>>
>>55380081
What did you expect? Java is a verbose shit language
>>
>>55380061
I want to believe in this but I doubt this is the case
>>
>>55375654
C++11
#include <iostream>
#include <algorithm>

int main(void)
{
std::string vowels = "aeiouAEIOU";

std::cout << "Enter text to count vowels: ";
std::string s;
std::getline(std::cin, s);

size_t vowel_count = 0;
std::for_each(s.begin(), s.end(), [&](char c) {
if(std::any_of(vowels.begin(), vowels.end(), [&](char z) {
return z == c;
})) {
vowel_count++;
}
});

std::cout << "There are " << vowel_count << " vowels." << std::endl;
}
>>
>>55380078
>is this perl6 yet?
Nope, this is Perl5. Perl6 doesn't have eval
>>
>>55380101
See:>>55379932

Does this look anything else but satire to you?
>>
tr '\n' ' ' | sed 's/[^aeoiu]\|\n//g' | wc -m
>>
File: fingerryanlt3.jpg (5 KB, 159x240) Image search: [Google]
fingerryanlt3.jpg
5 KB, 159x240
>>55380061
>>55380101
My solution wasn't satire.
>>
>>55380012
Clean version :
while (<>) {
$v=0;
foreach (split //) {
$v++ if (/[aeiou]/i);
}
print "$v\n";
}
>>
>>55380101
My guess is that there are lots of beginners who want to show off their skills, and a good part of them are satire or trolls
>>
>>55380060
Who are these semen demons?
>>
>>55380060
delete this
>>
>>55380081
Nice, now invert a binary tree with bash.
>>
def vowels(input):
count = 0
vowels = ['a', 'e', 'i', 'o', 'u']
for c in input.lower():
if c in vowels:
count++
return count
>>
File: 1450536304620-b.jpg (65 KB, 651x807) Image search: [Google]
1450536304620-b.jpg
65 KB, 651x807
>>55380187
Why senpai -_-
>>
>>55380198
But that wasn't the question
>>
writing C# one liners is my favorite programming thing to do

Console.WriteLine(Console.ReadLine().Where(ch => new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(char.ToLower(ch))).Count());
>>
>>55380276
those girls look 15 my dude
>>
>>55380131
as far as I know, you can't ignore case with sed.
so you should go something like that :
A=$(cat input |tr -d '\n'| sed 's/[^aeiouAEIOU\n]//g'); echo ${#A}
>>
>>55380306
They are 13 and 14 :^]
>>
>>55380198
Doing it in Java is still a very bad idea.
Actually doing anything in java is a bad idea.
>>
>>55380060
Get b& for canned peans bitch
>>
behold

public class vowels {
public static void main (String args[]) {
if (args.length==0) {
System.out.println("no input, exiting");
return;
}
int num=0;
for (int i=0;i<args.length;i++) {
for (int k=0;k<args[i].length();k++) {
switch (args[i].charAt(k)) {
case 'a': num++;break;
case 'e': num++;break;
case 'i': num++;break;
case 'o': num++;break;
case 'u': num++;break;
default: break;
}}}
System.out.println(num);
}}
>>
>>55380310
I just forgot about case
this is enough, but the solution with grep up above is better imo
tr -d '\n'| sed 's/[^aeiouAEIOU]//g' | wc -m
>>
>>55380281

Then what the hell was your point? You need to write the solution in Bash in order to be a good coder?
>>
>>55380447
I had no point.
I just don't like java
>>
>>55380395
>not following java convention to upper case class names
>space between method name and (
>array brackets after variable name instead of type name
>repetitive num++ without fallthrough
>no upper case
>default: break what the FLYING FUCK MAN
>multiple closing curly braces
>operating on args and not stdin

what the fuck are you doing
no, WHAT THE FUCK ARE YOU DOING
>>
>>55380540
it's just java
it's not suppose to be good :^)
>>
File: LaurieF.jpg (225 KB, 479x373) Image search: [Google]
LaurieF.jpg
225 KB, 479x373
def count_vowels(word):
word = str(word)
vowels = ['a','e','i','o','u']
count = 0
for i in word:
if i in vowels:
count += 1
print("There are {} vowels in your fucking word".format(count))
print("bird pls no stab :^O")

foo = raw_input("What's your word, senpai?\n")
count_vowels(foo)


Fuck your minimalism
>>
>>55380604
>it wordfiltered senpai in my code

Kek
>>
>everyone forgetting sometimes y
>>
>>55380634
>>>/lit/
>>
>>55380634
>sometimes
nigga please, we're not building AI here, and we're not adding in every dictionary word to know when the sometimes will happen.

I know there are rules, but since when does English follow rules?
>>
>>55376263
C++ is pure unmitigated cancer, and this just proves it.
>>
>>55380783
if I remember correctly, it does 40% of the time. Only 40%…
>>
How do I get my code to appear in the fancy white box
>>
>>55380838
use
/*your code*/
>>
>>55380875
/*your code*/
>>
select regexp_count('number of vowels in a string','[aeiou]',1,'i') as cnt from dual;
>>
>>55380838
you can also go with :
"[" code "]"
your code
"[" /code "]"
>>
>>55376025
>using the smiley with a carat nose
>>
>>55380838
take a look at the end of the pinned post on this board, seems like the ones who tried to answer have some difficulties to make it clear~
>>
>>55377378
Nice, shorter than my suggestion :)

inputVal = input("Text: ").lower()
print("Number of vowels: {}".format(sum(inputVal.count(c) for c in 'aeiouy')))
>>
File: 1459711959579.jpg (31 KB, 332x493) Image search: [Google]
1459711959579.jpg
31 KB, 332x493
>>55380123
>iostream
why do people continue to do this for just outputting to console.
>>
>>55375654
Vowels = list('aeiouAEIOU')
text = input()
sucsessful_iterations = 0
for counter in list(text):
if counter in Vowels:
sucsessful_iterations+=1

print (str(sucsessful_iterations))
>>
File: amiralbum.jpg (193 KB, 1200x1080) Image search: [Google]
amiralbum.jpg
193 KB, 1200x1080
>>55380123
>})) {
>>
>>55380569
>using the smiley with a carat nose
>>
>>55380604
>using the smiley with a carat nose
>>
    class String
def vowel_count
i = 0
for x in self.split('') do
i += %w{a e i o u}.include?(x) ? 1 : 0
end
return i
end
end

puts (gets.chomp).vowel_count

>>
>>55381224
>>55381234

>HIVEMIND
>I
>V
>E
>M
>I
>N
>D

Install gentoo
>>
int vowelCount(String string) {
int vowels = 0;
for(int i = 0; i < string.length(); i++) {
if(string.charAt(i) == 'a') {
vowels = vowels + 1;
} else if(string.charAt(i) == 'e') {
vowels = vowels + 1;
} else if(string.charAt(i) == 'i') {
vowels = vowels + 1;;
} else if(string.charAt(i) == 'o') {
vowels = vowels + 1;
} else if(string.charAt(i) == 'u') {
vowels = vowels + 1;
} else if(string.charAt(i) == 'y') {
vowels = vowels + 1;
} else if(string.charAt(i) == 'A') {
vowels = vowels + 1;
} else if(string.charAt(i) == 'E') {
vowels = vowels + 1;
} else if(string.charAt(i) == 'I') {
vowels = vowels + 1;
} else if(string.charAt(i) == 'O') {
vowels = vowels + 1;
} else if(string.charAt(i) == 'U') {
vowels = vowels + 1;
} else if(string.charAt(i) == 'Y') {
vowels = vowels + 1;
}
}
return vowels;
}
>>
File: 1456686717945.jpg (233 KB, 560x560) Image search: [Google]
1456686717945.jpg
233 KB, 560x560
>>55381284
dog bless
>>
>>55381284
Code quality through the roof.
Can't you think of a way to remove code duplication?
>>
>>55376344
noice
>>
>>55381157
Because they haven't learned anything other than copy and pasting. The same goes for people who throw "String args[]" in java mains when they're not sending anything to the program.
>>
>>55381316
>The same goes for people who throw "String args[]" in java mains when they're not sending anything to the program
The Java specification requires public static void main(String[] args) as the entry point, even if you don't send anything to the program.

It won't run without it.
>>
>>55381157
>>55381316

std::out is defined in iostream m9
>>
vowels="aeiou"
x = input()
print(sum([1 if el in vowels else 0 for el in x]))
>>
len([x for x in raw_input('enter your fucking word: ') if x in 'AEIOUaeiou'])
>>
>>55381430
>>55381493
damn forgot for upperclas... guess i'm dead
>>
int vowels(String string) {
return string.length() - string.replace("a", "").replace("a", "").replace("e", "").replace("i", "").replace("o", "").replace("u", "").replace("y", "").replace("A", "").replace("E", "").replace("I", "").replace("O", "").replace("U", "").replace("Y", "").length();
}
>>
>>55380131
>>55380310
>>55380397
Step aside, niggers:
tr -cd 'aeiouAEIOU' | wc -c
>>
#include <stdio.h>

int cnt[128];
char *c, buff[60];

int main(void){
fgets(buff, sizeof(buff), stdin);
c = buff;
while (*c) cnt[*c++]++;
printf("%d\n", cnt['a']+cnt['e']+cnt['i']+cnt['o']+cnt['u']+cnt['A']+cnt['E']+cnt['I']+cnt['O']+cnt['U']);
}
>>
>>55381547
this is the best answer of the whole thread, alongside with >>55379902
>>
>>55381550
Have fun with UTF-8.
>>
>>55381199
I couldn't make it less ugly.
>>
>>55381550
>ghetto hashing
>>
tr -cd '[aeiou]' | wc -c
>>
import scala.io.StdIn.readLine

def isVowel(c : Char) {
c match {
case 'a' => true
case 'e' => true
case 'i' => true
case 'o' => true
case 'u' => true
}
}

readLine().toLowerCase.toArray.filter(isVowel(_)).length
>>
>>55381284
Y is not a vowel
>>
>>55379490
absolutely terrible
>>
#include <amxmodx>

public plugin_init()
{
register_plugin("Vowel Counter", "1.0", "Anonymous");
register_clcmd("say", "clcmd_say");
}

public clcmd_say(id)
{
new szText[256], iVowels;
read_args(szText, charsmax(szText));
for (new i; i < sizeof(szText); ++i) {
switch(szText[i]) {
case 'a','A','e','E','i','I','o','O','u','U':
++iVowels;
case 0:
break;
}
}
client_print(id, print_chat, "Your message contained %d vowels.", iVowels);
return PLUGIN_CONTINUE;
}
>>
Here, found this on StackExchange seems to work fine: https://play.golang.org/p/MFboCiikYW

Obviously not coding this shit myself and do what I do best: copying ideas from the stacks.
>>
>>55381547
Bash only, no external tools

read text
text="${text//[^aeiouAEIOU]/}"
echo "${#text}"
>>
user_input = input()
vowels = ['a','e','i','o','u']
counted_vowels = 0
for x in user_input:
counter = vowels.count(x)
counted_vowels += counter

please rate my code I spent like an hour on it
>>
>>55379244
Comic sans?
>>
"[" code "]"
testing....
hello world;
"[" /code "]"
>>

this better work;

>>
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class VowelCounter {

private static String vowelRegex = "[aeiouAEIOU]";
private static Pattern vowelPattern = Pattern.compile(vowelRegex);

public static int countVowels(String string) {
int counter = 0;
Matcher vowelMatcher = vowelPattern.matcher(string);
while(vowelMatcher.find()) {
counter++;
}
return counter;
}
}
>>
>>55384433
Should have made the data members final.
>>
>>55375663
#include <stdio.h>

int isvowel(char c)
{
// assume it's lowercase
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
return 1;
else
return 0;
}

main()
{
int vowels = 0;

char c;
while((c = getchar()) != EOF)
vowels += isvowel(c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c);

printf("# of vowels = %d\n", vowels);
}
>>
File: bird stealing knife.gif (2 MB, 300x173) Image search: [Google]
bird stealing knife.gif
2 MB, 300x173
>>
I haven't written code in literally over a year, but this seems to work:

user_input = input("Enter your text: ")
lower_input = user_input.lower()
a_count = lower_input.count('a')
e_count = lower_input.count('e')
i_count = lower_input.count('i')
o_count = lower_input.count('o')
u_count = lower_input.count('u')
vowel_count = (a_count + e_count + i_count + o_count + u_count)
print (vowel_count)


I know that there's probably a much easier way to do this but IDK it works.
>>
>>55383881
0/10 you never printed anything.
>>
>>55382436
Bash seems pretty dope I should learn more of it.
>>
>>55381157
what to use then u faggt
>>
input <- readline("type something you asshat")
input <- tolower(strsplit(input,""))
print(sum(input %in% c("a","e","i","o","u"))
>>
>>55384816
The bird didn't say anything about printing
>>
>>55384963
woop, I fucked up. should be

input <- readline("type something you asshat")
input <- tolower(strsplit(input,"")[[1]])
print(sum(input %in% c("a","e","i","o","u"))


i forgot strsplit() returns a list
>>
>>55384993
and a trailing parenthesis on the last line. fuck me.
>>
>>55376863
Noice
>>
<!DOCTYPE html>
<script>
var a = 'input';
for (var i = 0; i < a.length; i++) {
if ((/^[aeiou]$/i).test(a.split('')[0])) {
document.getElementsByTagName('ul')[0].innerHTML += '<li>' + a.split('')[i] + '</li>'
}
}
</script>
<style>
ul li{
list-style-type: decimal;
}
ul li:not(ul li:last-child){
display: none;
}
</style>
<ul>

</ul>

fuck probably won't even work
>>
>>55375654
Easy shit
import java.util.Scanner;

public class Vowels {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a string of text.");
String userInput = scanner.nextLine();
scanner.close();

String newString = userInput.replaceAll("[AEIOUaeiou]", "");
int nbVowels = userInput.length() - newString.length();
System.out.println("Your string contains " + nbVowels + " vowels.");
}
}
>>
>>55385270
>languages every computer comes with an interpreter for
>can't be bothered to test it to see if it actually works
>>
>>55385379
forgot to add 'Sent from my iPad'
>>
perl as usual has a cool way to do it:
#!/usr/bin/perl

print <> =~ tr/[a|e|i|o|u]//;
>>
>>55385400
explanation
<> reads from some handle, this gets user input because the default is stdin
=~ runs a regex on that
tr/// is a transliteration, or replacement, regex
this whole expression returns the number of replacements made, which is printed
>>
>>55375663
what is the point of a thread if the most reasonable answer is at the top?
>>
>>55385400
very nice!
>>
>>55379795
The only correct answer
>>
>>55380810
#include <string>

using std::string;

int countVowels(string input) {
int count = 0;
string dict = "aeiouAEIOU";

for (auto itr = input.begin(); itr != input.end(); itr++)
for (auto dict_itr = dict.begin(); dict_itr != dict.end(); dict_itr++)
if (*itr == *dict_itr)
count++;
return count;
}


Defaggoted it.
>>
>>55385674
although this really isn't the way I'd do it.

>>55376249
fucking hell bash is awful.
>>
>>55375654
import sys
print sum (sum (letter.lower () in "aeiou" for letter in line) for line in sys.stdin)
>>
>>55375654
function countVowels(in) {
const vowels = "aeiouAEIOU";
let count = 0;
for(let i = 0; i < in.length; ++i) {
if (vowels.includes(in[i]))
count++;
}
return count;
}
>>
>>55379490
>doesn't count multiple instances of the same vowel
>>
>>55385704
Bash isn't that bad. Here's the right way to do it:
#! /bin/bash
tr -cd 'aeiouAEIOU' | wc -m

That poster was just a retard.
>>
File: arino-going-to-stab-you.png (123 KB, 302x245) Image search: [Google]
arino-going-to-stab-you.png
123 KB, 302x245
>>55375654
#include <stdio.h>
int to_lower(int a) {
if (a >= 65 && a <= 90) a+= 32;
return a;
}
int main() {
char c=0;
int vowels=0;
printf("Type a line of text, hit enter: ");
while (c != '\n' && c != EOF) {
c = getchar();
c = to_lower(c);
if (c == 'a' || c == 'i' || c == 'u' || c== 'e' || c == 'o') {
vowels++;
}
}
printf("There were %d vowels in that line.\n", vowels);
}


gonna stab you if you fucking keep this shit up, bird
>>
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main (int argc, const char *argv[])
{
int i = 0, c;

while ((c = tolower (getchar ())) != EOF)
i += strchr ("aeio", c) != NULL;

printf ("%d\n", i);

return 0;
}
>>
>>55377543
Nice name. This looks like Python, except I don't know what end does
>>
>>55375663
If you clear the fifth bit on the char, you can reduce the cases needed.
>>
>>55375654
There's a site called Rosetta code or something which shows a single algorithm in a ton of languages
>>
>>55385903
Fantastic, I'm going to remember that one.
>>
>>55385746
this is absurdly inefficient.
>>
>>55375654
package main

import "fmt"

func main() {
vowels := map[rune]struct{}{
'a': struct{}{},
'e': struct{}{},
'i': struct{}{},
'o': struct{}{},
'u': struct{}{},
'A': struct{}{},
'E': struct{}{},
'I': struct{}{},
'O': struct{}{},
'U': struct{}{},
}
cnt := 0
var s string
fmt.Println("ENTER SOME TEXT:")
for {
_, err := fmt.Scanf("%s", &s)
if err != nil {
if err.Error() != "unexpected newline" {
fmt.Println("ERROR:", err)
}
break
} else {
for _, r := range s {
if _, isVowel := vowels[r]; isVowel {
cnt++
}
}
}
}
fmt.Println("NUMBER OF VOWELS:", cnt)
}
>>
did this in c64 basic for shits and giggles
10 rem you might want to do a poke 53272,23
25 print "Type a line of text."
27 print "I'll count the vowels."
30 input i$
35 n=0
40 v=0
100 if n >= len(i$) then goto 200
110 k$=mid$(i$,n+1,1)
115 if k$="A" then v=v+1
120 if k$="E" then v=v+1
125 if k$="I" then v=v+1
130 if k$="O" then v=v+1
135 if k$="U" then v=v+1
140 if k$="a" then v=v+1
145 if k$="e" then v=v+1
150 if k$="i" then v=v+1
155 if k$="o" then v=v+1
160 if k$="u" then v=v+1
162 n=n+1
165 goto 100
200 print "There are ";
205 print v;
210 print " vowels."
>>
Wow, I didn't realise that /g/ only wrote bloated, shit code.

Here's a solution in Pyth.

FNrz0I}N"aeiou"=Z+Z1;Z
>>
import System.IO

main = do
line <- getLine
let numVowels = countVowels line
print numVowels

countVowels :: String -> Int
countVowels "" = 0
countVowels (x:xs)
| any (== x) vowel = 1 + countVowels xs
| otherwise = countVowels xs
where vowel = ['a','e','i','o','u','A','E','I','O','U']
>>
File: as a developer.png (8 KB, 563x76) Image search: [Google]
as a developer.png
8 KB, 563x76
>everyone in this thread just checking for aeiou
>never heard of gypsy or cwm
You'll have to use linguistic libraries to detect vowels, not regexes. Sorry. Stabbings all around.
>>
>>55387403
Who fucking said my favorite language is english? Normal [human] languages do not have this problem.
>>
>>55379458
doesn't work on upper case
>>
>>55387437
Sure, but how many people itt hold a favorite language for which checking aeiou does work? Probably very few.
>>
Cool it guys, VBA's got this:

function countChars(userString as string)

dim noChars as integer

for x = 1 to len(userString)
select case asc(mid(userString, x, 1)
case 65, 69, 73, 79, 85
noChars = noChars + 1
case 89
if rnd > .5 then noChars = noChars + 1
end select
next x

countChars = noChars
end function
>>
i can write in french, spanish, english, turkish, etc...
>>
>>55387867
so? all of them use latin
you could've named some pooinloo language
>>
my brain stopped
>>
>>55387800
Oops, forgot to change the case of the string!
>>
>>55385809
>only one lib
nice
>>
File: isabelle.png (213 KB, 581x784) Image search: [Google]
isabelle.png
213 KB, 581x784
>>55385746
function countVowels(str) {
return str.match(/[aeiou]/gi).length;
}

you can do better.
>>
>>55385903
What?
>>
>>55379795
nigga that's some long code

main = interact (show . length . filter ( `elem` "aouieAOUIE"))
>>
>>55385839
u is not a vowel?
>>
>>55375654
>it's another "quick /g/, do my homework" thread
>people actually replying
jesus fuck, why are you so retarded?
>>
var input = prompt();
var i = input.length, c = 0;
var vowels = ['a', 'e', 'i', 'o', 'u'];
while (i--) {
if (vowels.indexOf(input[i]) > -1)
c++;
}
console.log(c);
>>
>>55375654
function vowels = vowels(s)
vowels = 0;
v = 'aeiou';
s = lower(s);
for n = 1:length(v)
vowels = vowels + length(strfind(s,v(n)));
end
>>
>>55381284
>Y

JOSE
>>
>>55384993
Still doesn't work, even when trailing parenthesis is added.

Detects 0 vowels.

Stabbing time, data plebber
>>
File: okperl.png (3 KB, 468x42) Image search: [Google]
okperl.png
3 KB, 468x42
>>55380012
This solution gave me cancer, beautiful cancer.
Mind explaining it?
>>
>search unicode / utf
>1 result
And you guys wonder why 90% of all software is shit.
>>
>>55375654
Input is left as an exercise for the reader (because JS is not normally used for CLI tools):

let input = "farters";
let num_vowels = input.split("").filter(c => "aeiou".indexOf(c.toLowerCase()) != -1).length;
>>
>>55388403
Uppercase A is 01000001. Lowercase a is 01100001. Uppercase and lowercase letters in ASCII only differ on the fifth bit. So you could clear the fifth bit before the switch and only use five cases instead of 10.
>>
>>55390400
so
vowels += isvowel(c | 0x20);
>>
>>55379425
This
>>
The only readable and understandable languages used in this thread are C and Java
>>
>>55390659
How's your first year of CS going?
>>
should have used jquery, it has a plugin called jmath that can count a number of vowels.
Thread replies: 255
Thread images: 26

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.