def greatest(a,b):
if a>b:
return a
return b
def odd_check(a):
return not(a%2 == 0)
def go(x,y,z):
a = odd_check(x)
b = odd_check(y)
c = odd_check(z)
if a and b and not c:
print greatest(x,y)
elif a and not b and c:
print greatest(x,z)
elif not a and b and c:
print greatest(y,z)
elif not a and not b and c:
print z
elif not a and b and not c:
print y
elif a and not b and not c:
print x
elif a and b and c:
print greatest(x,greatest(y,z))
else:
print "None of them are odd"
go(int(input()),int(input()),int(input()))
Doing the problem it felt like I am going over all the eight combinations \$2^3\$ for three variables. Is there any way to avoid this?
def greatest(*arr); arr.select(&:odd?).max; end
. Given the similarity of Ruby and Python, I assume this would be little different in Python. Perhaps a someone familiar with both languages could comment. \$\endgroup\$def odd_check(a): return a%2
\$\endgroup\$def greatest(a,b): return max(a,b)
will probably be faster (and you may not need the function, just usemax()
inline). \$\endgroup\$