28
\$\begingroup\$

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.

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

69 Answers 69

1 2
3
0
\$\begingroup\$

Python 2, 41 bytes

lambda s:sum(map(s.count,"aAeEiIoOuU"))%2

Try it online!

Returns 0 for even, and 1 for odd.

Explanation: Counts how many total odd letters are in the word, and returns whether that number is even (0) or odd (1).

\$\endgroup\$
0
\$\begingroup\$

Japt v2.0a0, 5 bytes

è\v u

Try it

\$\endgroup\$
0
\$\begingroup\$

Kotlin, 32 bytes

0 is false, 1 is true.

{it.count{it in "aAeEiIoOuU"}%2}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Pepe, 131 bytes

rEeEEeeeeErEeEEeeEeErEeEEeEeeErEeEEeEEEErEeEEEeEeEREeEeeeeeEREeeEeeeeeREEREEEerrEEEEEerEEeeREEEEReeReReREEeREEEEeeeRREeeeReEEEEReEE

Ouputs 0 for odd, 1 for even.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
0
\$\begingroup\$

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)
\$\endgroup\$
0
\$\begingroup\$

><>, 47 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
1 2
3

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.