Cody

# Problem 44382. Parse me a Lisp

Solution 1292106

Submitted on 17 Oct 2017
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   Fail
expr = "(+ 1 1 1 1 1)"; assert(isequal(eval_lisp(expr), 5));

Error using str2num (line 31) Requires character vector or array input. Error in eval_lisp (line 20) x = str2num(s); Error in Test1 (line 2) assert(isequal(eval_lisp(expr), 5));

2   Fail
expr = "(+ 1 5)"; assert(isequal(eval_lisp(expr), 6));

Error using str2num (line 31) Requires character vector or array input. Error in eval_lisp (line 20) x = str2num(s); Error in Test2 (line 2) assert(isequal(eval_lisp(expr), 6));

3   Fail
expr = "(+ 1 1 1 1 1 1 1 1 1 1 1 1 1)"; assert(isequal(eval_lisp(expr), 13));

Error using str2num (line 31) Requires character vector or array input. Error in eval_lisp (line 20) x = str2num(s); Error in Test3 (line 2) assert(isequal(eval_lisp(expr), 13));

4   Fail
expr = "(+ 1 2 3 4 5 6 7 8 9 10)"; assert(isequal(eval_lisp(expr), 55));

Error using str2num (line 31) Requires character vector or array input. Error in eval_lisp (line 20) x = str2num(s); Error in Test4 (line 2) assert(isequal(eval_lisp(expr), 55));

5   Fail
expr = "(* 1 2 3 4 5 6 7 8 9 10)"; assert(isequal(eval_lisp(expr), 3628800));

Error using str2num (line 31) Requires character vector or array input. Error in eval_lisp (line 20) x = str2num(s); Error in Test5 (line 2) assert(isequal(eval_lisp(expr), 3628800));

6   Fail
expr = "(* (* 10 (+ 1 4)) (+ 10 (/ 12 2 3) 1) 0.1)"; assert(isequal(eval_lisp(expr), 65));

Error using str2num (line 31) Requires character vector or array input. Error in eval_lisp (line 20) x = str2num(s); Error in Test6 (line 2) assert(isequal(eval_lisp(expr), 65));