Problem 44382. Parse me a Lisp
Solution Stats
Problem Comments
-
3 Comments
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.
Solution Comments
-
1 Comment
cheat
-
1 Comment
Nice. I was trying to figure out how to use strtok, but couldn't quite come up with it.
-
3 Comments
Are you sure that your Test Suite works? I had to change all the double quotes to single quotes.
Double-quoted strings are string literals in MATLAB R2017a+. To convert a string to char array, use the "char" function.
Thank you for that hint about the "char", bmtran. Never would have figured out what was wrong with my solution otherwise...
Problem Recent Solvers86
Suggested Problems
-
781 Solvers
-
Permute diagonal and antidiagonal
295 Solvers
-
Relative ratio of "1" in binary number
975 Solvers
-
350 Solvers
-
Calculate Amount of Cake Frosting
18394 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!