Cody

# Problem 221. Boolean algebra

Solution 1803654

Submitted on 2 May 2019
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
nand = @(x,y) (~(x&y)); expr = '~(a&b)'; sol = regexprep(mat2nand(expr),'[^(nand)ab\(\),01(true)(false)]*',''); for a=[0 1], for b=[0 1] res(a+1,b+1) = eval(sol); end; end if isempty(strfind(which('isequal'),'built-in')) || isempty(strfind(which('assert'),'built-in')) error('test-suite manipulation attempt detected') end assert(isequal(res , logical([1 1; 1 0])))

2   Pass
nand = @(x,y) (~(x&y)); expr = '(a&~a)|(b&~b)|((a&b)&(a|~a))'; sol = regexprep(mat2nand(expr),'[^(nand)ab\(\),01(true)(false)]*',''); for a=[0 1], for b=[0 1] res(a+1,b+1) = eval(sol); end; end if isempty(strfind(which('isequal'),'built-in')) || isempty(strfind(which('assert'),'built-in')) error('test-suite manipulation attempt detected') end assert(isequal(res , logical([0 0; 0 1])))

3   Fail
nand = @(x,y) (~(x&y)); rules ={{'a','~(a|b)'},{'b','(~b&a)&a'},{'a','(a&~a)|(~(b&~b))&b'},{'b','a&b|~a&~b'}}; for nrep=1:5 expr='a|b'; for l=1:randi(10)+5 rn=randi(4); expr = regexprep(expr,rules{rn}(1),rules{rn}(2),'once'); end sol = regexprep(mat2nand(expr),'[^(nand)ab\(\),01(true)(false)]*',''); for a=[0 1], for b=[0 1] res(a+1,b+1) = eval(sol); cor(a+1,b+1) = eval(expr); end; end if isempty(strfind(which('isequal'),'built-in')) || isempty(strfind(which('assert'),'built-in')) error('test-suite manipulation attempt detected') end assert(isequal(res , cor)) end

Error using Test3 (line 11) Error: Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}