Description
In Lisp and its variants, function calls are done using parenthesis where the first item in the parenthesis is the function being called and the following items are arguments to the function. Given a mathematical ( + - * / ) expression using this notation, return the result. Note: In Lisp, functions that normally take only two arguments can be called with many arguments, with the function being applied to all elements from left to right.
Simple example
(+ 1 1 1 1 1)
would give 5.
Complicated example
(* (* 10 (+ 1 4)) (+ 10 (/ 12 2 3) 1) 0.1)
would give 65.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers89
Suggested Problems
-
3480 Solvers
-
Get the area codes from a list of phone numbers
1071 Solvers
-
Return the first and last characters of a character array
11791 Solvers
-
Operate on matrices of unequal, yet similar, size
226 Solvers
-
441 Solvers
More from this Author56
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
it seems look-up table solutions are becoming a bit of an issue, could you please add a few test cases to discourage this? +1 for random test cases that are a bit harder to trick, for example something like n=randi(100,1,randi(10)); expr = "(+" + string(num2str(n))+ ")"; assert(isequal(eval_lisp(expr), sum(n)));
I think another test case with multiple expressions would be equally useful. Even something as simple as (+ 1 (* 2 3) 4) would prevent some of the look-up solutions. Make some of those values random, and it will work even better.
Good problem, and better than 44374. Precedence is clear.