With the success of Simple Boolean Algebra Calculator, I present a more difficult problem.
Above is what actual boolean algebra looks like. For the purposes of this code golf, this is not the exact syntax that will be used.
Given a short boolean expression, return the solution to the expression.
There will be at most two values and one function involved in the calculator. The values may be any of 0, 1, or a capital letter(s). The functions may be /, +, or .
Any of the following may be an input: (values are demonstrated with X and Y in these examples.)
One function, One value
- There is only one possibility for this, which is /X. Return NOT X. If X is a variable, return /X, otherwise compute and output. This is the only scenario where /, the backslash, will be used.
- There is only one possibility for this, which is XY. Return X AND Y. If X and Y are different variables, return XY, otherwise compute and output. This is the only scenario where two values are next to each other.
One value, One function, Another value
- If you've done Simple Boolean Algebra Calculator, this is exactly the same except that it now must be able to output two variable calculations.
- Return the value for X (function) Y. If X and Y are different variables, output X (function) Y.
- (function), the second character in this scenario, will be either "+" or ".". If "+", treat as OR. If ".", treat as AND.
Input: Either two characters or three characters.
Output: Either one character, two characters, or three characters.
Input => Output /0 => 1 /1 => 0 /P => /P
These expressions output the NOT value for the input. /P outputs /P because it cannot be simplified further.
Input => Output 0Q => 0
0Q evaluates to 0 because 0 AND Q will always be 0, regardless of what value Q takes.
Input => Output Z1 => Z
Z1 evaluates to Z because the output for Z AND 1 depends entirely on the value of Z.
Input => Output AH => AH (or A.H)
AH evaluates to AH because it cannot be simplified further. A.H is also a valid output.
Input => Output A+1 => 1
A+1 evaluates to 1 because the OR statement is overridden by 1. That is, no matter what value A takes, the presence of 1 means that the statement will always evaluate to 1.
Input => Output B+B => B
B+B evaluates to B because the OR statement is dependent on either Bs being true. If both Bs are false, then the output would also be false. So, the statement returns B since whatever value B takes, the output would return that.
Input => Output W+L => W+L
W+L evaluates to W+L because it cannot be simplified further.
Input => Output 0.H => 0
0.H evaluates to 0 because the AND statement is overridden by 0. That is, no matter what value H takes, the presence of 0 means that the statement will always evaluate to 0.
Input => Output 1.1 => 1
1.1 evaluates 1 because the AND statement requires both inputs to be 1, and since they are both 1, 1 is returned.
Input => Output G.L => G.L
G.L evaluates to G.L because it cannot be simplified further.
Input => Output /0 => 1 /1 => 0 /P => /P 00 => 0 11 => 1 0Q => 0 Z1 => Z NN => N AH => AH (or A.H) A+1 => 1 B+B => B R+0 => R 1+1 => 1 0+0 => 0 A+B => A+B Y+Z => Y+Z 0.0 => 0 Q.Q => Q 0.A => 0 1.C => C 1.1 => 1 R.S => R.S N.W => N.W
This is code-golf, so shortest answer wins. Good luck.