Well that's odd... no wait, that's even!
CJam, 18 17 13 bytes
Thanks to aditsu for saving 4 bytes.
qW:O%eu~"eo"=
Try the test suite here. (The test suite is too long for the permalink. Just copy them from the challenge spec.)
Explanation
q e# Read the input.
W:O e# Push a -1 and store it in variable O.
% e# Use the -1 to reverse the string, because CJam's stack-based nature and the
e# commutativity of the operators means we can evaluate the code in postfix notation.
eu e# Convert the string to upper case, turning 'e' into 'E' (a variable with even value
e# 14) and 'o' into 'O' (which we've stored the odd value -1 in).
~ e# Evaluate the string as CJam code, leaving the result on the stack.
"eo"= e# Use the result as an index into the string "eo". CJam's indexing is cyclic so it
e# automatically takes inputs modulo 2. Negative indices also work as expected.
Pyth, 16 14 bytes
@"eo".vjdXzGU9
Pyth can itself evaluate a string, that is in Pyth syntax. Therefore I replace e
and o
with 4
and 5
. Then the evaluation will give me an even or odd number, and I can easily print the result.
Try it online: Demonstration or Test Suite
Explanation:
@"eo".vjdXzGU9 implicit: z = input string
XzGU9 replace "e" in z with 4 and "o" with 5
jd put a space between each char
.v evaluate it (Pyth style)
@"eo" and print "e" or "o"
Additional explanation to the replace. G
is a variable initialized with the alphabet abc...xyz
. U9
is the list [0, 1, ..., 8]
. XzGU9
replaces the letters of the alphabet with the values of the list. So a
gets replaced with 0
, b
with 1
, ..., e
with 4
, ..., i
with 8
, j
with 0
, ..., and o
with 5
. Therefore I e
gets replaced with an even number and o
with an odd number. All the other replacements have no effect at all.
Perl, 50 45 40 characters
(39 characters code + 1 character command line option.)
1while s/\+oe|\+eo|\*oo/o/||s/\W\w\w/e/
Sample run:
bash-4.3$ echo -n '**o++*ee*++eoe*eo+eoo' | perl -pe '1while s/\+oe|\+eo|\*oo/o/||s/\W\w\w/e/'
o