Write code to evaluate whether a chain of inequalities is true or false. An example input is the string
3<=4!=9>3==3
This is true because each of its components is true:
(3<=4) and (4!=9) and (9>3) and (3==3)
Input:
A string that represents a chain of one or more inequalities. The allowed comparison operators are
== equals
!= does not equal
> is greater than
>= is greater than or equal to
< is less than
<= is less than or equal to
The allowed numbers are single-digit numbers 0
through 9
. There won't be any spaces, parentheses, or other symbols.
Output:
The correctness of the inequality as a consistent Truthy or Falsey value. Consistent means every Truthy output is the same and every Falsey output is the same.
Restriction:
The intent of this challenge is for you to write code that processes the inequalities, rather than have them be evaluating them as code, even for a single inequality in the chain. As such, methods like Python's eval
and exec
that evaluate or execute code are banned. So are functions which look up a method or operator given its name as a string. Nor is it allowed to launching processes or programs to do the evaluation for you.
Test cases:
3<=4!=9>3==3
True
3<=4!=4
False
5>5
False
8==8<9>0!=2>=1
True