Is it an Odd Word?
EXCEL, 79 bytes:
=MOD(SUMPRODUCT(LEN(A1)-LEN(SUBSTITUTE(LOWER(A1),{"a","e","i","o","u"},""))),2)
input:
This function can be placed anywhere EXCEPT A1
Put your word in question into A1.
Output: 0 if even, 1 if odd.
JavaScript (ES6), 34 41 33 32 bytes
Saved 1 bytes thanks to Arnauld:
s=>~s.split(/[aeiou]/i).length&1
- Odd word : returns
1
- Even words : returns
0
Previous solutions:
33 bytes thanks to Arnauld:
s=>s.split(/[aeiou]/i).length&1^1
- Odd word : returns
1
- Even words : returns
0
Another way without bitwise operators:
s=>++s.split(/[aeiou]/i).length%2
41 bytes:
(s,a=s.match(/[aeiou]/ig))=>a&&a.length%2
- Odd word : returns
1
- Even words with odd letters : returns
0
- Even words with no odd letters : returns
null
42 bytes to return 0
instead of null
:
(s,a=s.match(/[aeiou]/ig))=>a?a.length%2:0
34 bytes, breaks on words with no odd letters:
f=s=>s.match(/[aeiou]/ig).length%2
Saved 2 bytes thanks to Shaun H
s=>s.match(/[aeiou]/ig).length%2
Brain-Flak 206 196 192 178 + 3 = 181 bytes
Try it Online!
([]<{({}[((((((()()())){}){}){}){}){}()]){({}[({}())]){({}[({})]){({}[({}()())]){({}[({})]){({}<>)(<>)}}}}}{}{}}><>[[]]<>()()){(({}[<>(())<>()()])){{}({}())((<>)<>)}{}}{}<>({}<>)
This requires the -c
flag to run in ASCII mode adding an extra 3 bytes to the length of the program.
Ungolfed
([]<
{({}[(((((()()()){}){}){}){}){}()])
{
({}[()()()()])
{
({}[()()()()])
{
({}[(()()()){}])
{
({}[(()()()){}])
{
({}<>)
(<>)
}
}
}
}
}
{}
}
><>[[]]<>)
(<(()()<>)>)<>{({}[()])<>(({}()[({})])){{}(<({}({}))>)}{}<>}{}<>({}<{}><>)
Explanation
First store the stack height for future purposes
([]<...>
Then while the stack is not empty (assumes that none of the characters is zero)
{...}
Subtract ninety seven (and store 3 for later optimizations)
({}[((((((()()())){}){}){}){}){}()])
If it is not zero (i.e. not a)
{...}
Subtract 4 (and store 4 for later optimizations)
({}[({}())])
If it is not zero (i.e. not e)
{...}
Subtract 4 (and store 4 for later optimizations)
({}[({})])
If it is not zero (i.e. not i)
{...}
Subtract 6 (and store 6 for later optimizations)
({}[({}()())])
If it is not zero (i.e. not o)
{...}
Subtract 6 (store 6 because the program expects one later)
({}[({})])
If it is not zero (i.e. not u)
{...}
Move the remainder to the other stack and put a zero on the active stack to escape all of the ifs
({}<>)(<>)
Once all of the ifs have been escaped remove the zero and the six
{}{}
Once all the characters have been processed subtract the height of the offset from the originally stored height.
...<>[[]]<>)
Mod by two
{(({}[<>(())<>()()])){{}({}())((<>)<>)}{}}{}<>({}<>)