# Is it an Odd Word?

## Challenge

Given a single word as input, determine if the word is odd or even.

## Odd and Even words

Assume the general rules:

odd + odd = even
even + odd = odd
odd + even = odd
even + even = even


In the alphabet, the odd letters are:

aeiou


And the even letters are:

bcdfghjklmnpqrstvwxyz


The same applies to capital letters (AEIOU are odd and BCDFGHJKLMNPQRSTVWXYZ are even).

You then 'add' each of the letters in the word together. For example, the word cats is equivalent to:

even + odd + even + even


Which simplifies to:

odd + even


Which simplifies further to:

odd


So the word cats is odd.

## Examples

Input:  trees
Output: even


Input:  brush
Output: odd


Input:  CAts
Output: odd


Input:  Savoie
Output: even


Input:  rhythm
Output: even


## Rules

All input will be a single word which will only contain alphabetical characters.

If the word is odd, output a truthy value. If the word is even, output a falsey value.

## Winning

The shortest code in bytes wins.

• Could you add an example of a word without any odd letters.
– Hedi
Sep 20, 2016 at 18:50
• @Hedi I've added one, rhythm Sep 20, 2016 at 19:37
• Excuse you. Odd Word™ has been trademarked already by JLee. This is an unauthorized use of the term. :P Sep 20, 2016 at 20:58
• This is begging for a pure regex submission Sep 20, 2016 at 21:19
• Is the input guaranteed to only contain alphabetical characters? Sep 20, 2016 at 23:07

## Racket 127 bytes

(if(= 0(modulo(for/sum((i(map(λ(i)(ormap(λ(x)(equal? i x))(string->list"aieouAEIOU")))(string->list s))))(if i 1 0))2))#f #t)


Ungolfed:

(define(f s)
(let* ((vl (string->list "aieouAEIOU"))
(od (λ(i) (ormap (λ (x) (equal? i x)) vl)))
(ol (map od (string->list s)))
(s (count (λ(i) i) ol ))
(m (modulo s 2)))
(if (= m 0) "even" "odd")
))


A longer (240 bytes) but more direct version:

(let*((vl(string->list"aieouAEIOU"))(od(λ(i)(ormap(λ(x)(equal? i x))vl))))(let lp((l(string->list s))
(st #t)(d 0))(cond((null? l)(if d"odd""even"))(st(lp(cdr l)#f(if(od(car l))#t #f)))
(else(lp(cdr l)#f(if(equal? d(od(car l)))#f #t))))))


Ungolfed:

(define (f s)
(let* ((vl (string->list "aieouAEIOU"))
(od (λ (i) (ormap (λ (x) (equal? i x)) vl) )))
(let loop ((l (string->list s))
(starting #t)
(odd 0))
(cond
((null? l)
(if odd "odd" "even"))
(starting
(loop (rest l) #f
(if(od (first l))
#t #f )))
(else
(loop (rest l) #f
(if (equal? odd
(od (first l)))
#f #t)))))))


Testing:

(f "trees")
(f "brush")
(f "CAts")
(f "Savoie")
(f "rhythm")


Output:

"even"
"odd"
"odd"
"even"
"even"


# Java, 128 bytes

boolean f(String k){return k.chars().flatMap(i->"aeiouAEIOU".contains(((char)i)+"")?IntStream.of(1):IntStream.of(0)).sum()%2>0;}


There's definitely a better way than using Instream.of(0) and Instream.of(1).

# Ruby, 30 bytes

->w{w.count('aeiouAEIOU')%2>0}


Returns true for an odd word and false for an even word. The existing Ruby solution returns 0 for even words, which is a truthy value in Ruby.

# Elixir, 45 bytes

&rem(length(Regex.scan(~r/[aeiou]/i,&1)),2)>0


Anonymous function defined using the capture operator. If the number of vowels is odd, the specified word is odd, so the function returns true.

Full program with test cases:

s=&rem(length(Regex.scan(~r/[aeiou]/i,&1)),2)>0
# test cases
IO.puts s.("trees") # false
IO.puts s.("brush") # true
IO.puts s.("CAts")  # true
IO.puts s.("Savoie")    # false
IO.puts s.("rhythm")    # false


Try it online on ElixirPlayground !

# Pepe, 131 bytes

rEeEEeeeeErEeEEeeEeErEeEEeEeeErEeEEeEEEErEeEEEeEeEREeEeeeeeEREeeEeeeeeREEREEEerrEEEEEerEEeeREEEEReeReReREEeREEEEeeeRREeeeReEEEEReEE


Ouputs 0 for odd, 1 for even.

Try it online!

# Powershell, 39 bytes

($args|sls "[aeiou]"-a).Matches.Count%2  Explanation: • Takes arguments from the predefined $args;
• Selects all matches to vowel characters (sls is alias for Select-String. By default, matches are not case-sensitive);
• Takes the Matches.Count, and %2 to check whether it's odd/even.

Test script:

$f = { ($args|sls "[aeiou]"-a).Matches.Count%2

}

@(
,("trees", $false) ,("brush",$true)
,("CAts", $true) ,("Savoie",$false)
,("rhythm", $false) ) | % {$s,$expected =$_
$result = &$f $s "$($result-eq$expected): $result" }  Output: True: 0 True: 1 True: 1 True: 0 True: 0  # Z80Golf, 34 bytes 0000 restart: 0000 cd 03 80 call$8003
0003   30 05                  jr   nc,letter
0005                done:
0005   78                     ld   a,b
0006   e6 01                  and   1
0008   ff                     rst   $38 0009 76 halt 000a letter: 000a e6 1f and$1f
000c   3d                     dec   a
000d   28 10                  jr   z,vowel
000f   d6 04                  sub   4
0011   28 0c                  jr   z,vowel
0013   d6 04                  sub   4
0015   28 08                  jr   z,vowel
0017   d6 06                  sub   6
0019   28 04                  jr   z,vowel
001b   d6 06                  sub   6
001d   20 e1                  jr   nz,restart
001f                vowel:
001f   04                     inc   b
0020   18 de                  jr   restart


Try it online!

# Pip, 9 bytes

-XV Na%:2


Try it online!

 XV        Regex matching [aeiou]
-          Case-insensitive
N      Count matches in
a     Command-line argument
%:2  Mod 2 (the : helps with parsing)


# ><>, 47 bytes

0i1+48*%:?v~2%n>~!
26a28*2b* \
r&:{=&+r  >l3(?v


Try it online!

Java 8: 88 bytes

s->s.chars().map(c->"aeiouAEIOU".contains((char)c+"")?-1:1).reduce(1,(x,y)->x*y)<0;


Try it online!

Dang it, I didn't see the older Java solution that used regex. Good job.

# Factor, 34 bytes

[ [ "aeiouAEIOU"in? ] count odd? ]


Try it online!

# Python 3, 42 bytes

lambda x:sum(c in"aeiouAEIOU"for c in x)%2


Try it online!