You end up having a lot of very long, boring-looking conditionals in your code:
if flag == 1:
while have != needed:
if type == 7:
These can be transformed into their much more lovable <3
conditionals counterparts:
if abs(flag - 1) + 2 <3:
while 3 - abs(have - needed) <3:
if 2 + abs(type - 7) <3:
Task
Your task is to take a conditional and make it in terms of <3
. The only spacing that matters is that there is none between <
and 3
.
Conditionals will be two expressions seperated by either ==
, !=
, >
, <
, >=
or <=
.
Expressions will only contain addition, subtraction, unary negation (-something
), where there is one +
or -
before each variables or numbers (except the first which has nothing or -
before it).
Numbers will be [0-9]+
, and variables will be [a-z]+
. If the answer needs to use |x|
(The absolute value of x
), use the abs()
function. You may assume that all variables are integers, and all number constants in the input are < 1000.
The output does not need to be in it's simplest form. It does need to be a conditional like above, meaning that it is two expressions only, seperated by one conditional sign, but it can also use the abs
function, enclosing a valid expression, and then it acts like a variable, in terms of validity.
If the input does not have an output for any value of a variable, output a condition that is always false, but still in terms of <3
.
Part of the challenge is figuring out how to do it, but here are the steps for the have != needed
above:
have != needed
have - needed != 0
abs(have - needed) > 0
-abs(have - needed) < 0
3 - abs(have - needed) <3
Scoring
This is code-golf, so the shortest valid code, in bytes, wins.
Test cases
(Note, these outputs aren't the only outputs, but I tried to simplify them.)
flag == 1
abs(flag - 1) + 2 <3
have != needed
3 - abs(have - needed) <3
type == 7
2 + abs(type - 7) <3
x > y
3 - x + y <3
x + 5 < -y
x + 8 + y <3
x + 6 <= y
x + 8 - y <3
-x >= y + 3
x + y + 5 <3
x < x
3 <3
# Unsimplified; both would be valid outputs.
x - x + 3 <3