Problem 221. Boolean algebra
Your contractor from Elbonia has sent you the prototype of the new logical unit. It turns out that the only logical relation it understands is "nand":
nand(a,b) := ~(a&b)
Your team has been developing code using the usual logical operators following MATLAB syntax: ~,& and |. To save the project you need to write a translator that expresses MATLAB logical expressions using only the nand function.
Input
- expr: a string containing a valid logical expression in MATLAB, that relates the two logical variables a and b
Output
- out: a string containing an equivalent logical expression that may only use the function nand(a,b).
Example 1:
expr = 'a|(~b)' =>out = 'nand(nand(a,a),b)'
Example 2:
expr = '(a & ~a) | ~(a|b)' =>out = 'nand(nand(nand(a,a),nand(b,b)),nand(nand(a,a),nand(b,b)))'
Remarks:
It is not necessary to provide the shortest solution. A solution always exists. The input string is non-empty and always evaluates to true or false, if a and b are logical variables. All substrings in the output that are not 'a','b','0','1','true','false','(',')' or'nand' will be ignored.
Solution Stats
Problem Comments
-
3 Comments
Whenever I try to submit a solution or use the scratch pad for testing, I get the message
The server is not available. Wait a few minutes, and then retry your request. If the problem persists, contact the instructor.
This happens regardless of what code is entered in the solution/scratch pad textareas, so I think it points to a Cody problem rather than a code problem.
Hello Christian,
I have faced this issue before and notified the Cody team about this. Though they occurred on a singular problem basis (and were solved correspondingly), I am again facing this issue for last couple of days, and now so are you.
I am collecting some data before notifying them again. Please let me know the following things so that I can add them while reporting this matter -
1. Does it occur on particular problems or any problem you are trying to solve? If on some particular problems, please let me know which ones.
2. Which OS and Browser are you using?
3. Does the issue get solved by using a different internet connection?
Any other info would also be helpful.
Hi Dyuman, thanks for being on the case! To answer your questions:
1. It's been happening on this problem and problem 1, which I tried submitting solutions to yesterday to work out where exactly the problem was. I got the error once, but ONLY once, on problem 1; on this problem, on the other hand, it has happened every single time. I've not tried to solve other problems recently.
2. Windows 11 (x64); I've tried both Firefox and Opera (the latter is based on Chrome). Same problem with both
3. I've not tried; too much to do at work right now to be able to sneak in Cody time...
Solution Comments
Show commentsProblem Recent Solvers9
Suggested Problems
-
13489 Solvers
-
155 Solvers
-
886 Solvers
-
Back to basics 23 - Triangular matrix
1015 Solvers
-
Side of an equilateral triangle
6289 Solvers
More from this Author7
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!