9
Unlike most languages, Python evaluates a<b<c
as it would be done in mathematics, actually comparing the three numbers, as opposed to comparing the boolean a<b
to c
. The correct way to write this in C (and many others) would be a<b && b<c
.
In this challenge, your task is to expand such comparison chains of arbitrary lengths from the Python/intuitive representation, to how it would be written in other languages.
Specifications
- Your program will have to handle the operators:
==, !=, <, >, <=, >=
. - The input will have comparison chains using only integers.
- Don't worry about the trueness of any of the comparisons along the way, this is purely a parsing/syntactical challenge.
- The input won't have any whitespace to prevent answers that trivialize parsing by splitting on spaces.
- However, your output may have a single space surrounding either just the
&&
's, or both the comparison operators and the&&
's, or neither, but be consistent.
Test Cases
Input Output
---------------------------------------------------------------
3<4<5 3<4 && 4<5
3<4<5<6<7<8<9 3<4 && 4<5 && 5<6 && 6<7 && 7<8 && 8<9
3<5==6<19 3<5 && 5==6 && 6<19
10>=5<7!=20 10>=5 && 5<7 && 7!=20
15==15==15==15==15 15==15 && 15==15 && 15==15 && 15==15
This is code-golf, so shortest code in bytes wins!
related – Maltysen – 2017-10-09T03:50:57.693
Can I have two spaces either side of the
&&
? – H.PWiz – 2017-10-09T04:34:40.360@H.PWiz nope, srry. – Maltysen – 2017-10-09T04:35:28.047