diff --git a/.gitignore b/.gitignore index 3c3629e..fd4f2b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +.DS_Store diff --git a/08_recursion_and_dynamic_programming/14_booleanEvaluation.js b/08_recursion_and_dynamic_programming/14_booleanEvaluation.js new file mode 100644 index 0000000..0e4cf89 --- /dev/null +++ b/08_recursion_and_dynamic_programming/14_booleanEvaluation.js @@ -0,0 +1,18 @@ +/* + Given a boolean expression consisting of the symbols 0 (false), 1(true), + & (AND), | (OR), and ^(XOR), and a desired boolean result value 'result', + implement a function to count the number of ways of parenthesizing the expression such + that it evaluates to 'result' + + E.g. + countEval('1^0|0|1', false) -> 2 + countEval('0&0&0&1^1|0', true) -> 10 +*/ + +'use strict'; + +function countEval() { + // Your code here +} + +module.exports = countEval; diff --git a/08_recursion_and_dynamic_programming/14_booleanEvaluation.test.js b/08_recursion_and_dynamic_programming/14_booleanEvaluation.test.js new file mode 100644 index 0000000..0eef9d4 --- /dev/null +++ b/08_recursion_and_dynamic_programming/14_booleanEvaluation.test.js @@ -0,0 +1,14 @@ +'use strict'; + +const assert = require('chai').assert; +const countEval = require('./14_booleanEvaluation'); + +describe('recursion and dynamic programming', function() { + describe('boolean evaluation', function() { + it('should return the number of ways of parenthesizing an expression', function() { + const expression = '1^0|0|1'; + const result = false; + assert.equal(countEval(expression, result), 2); + }) + }) +})