During this activity, students should be able to:
This activity helps students develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.
This project must be developed individually.
The following problem was adapted from: Problem 11326 of the Sphere Online Judge (SPOJ)
Write a Clojure function called arith-eval
that evaluates a parenthesized expression of single-digit positive integers and the binary operators +
, -
, *
. The order of operations differs from the canonical one in that operations have no precedence; they are simply evaluated from left-to-right, with only parentheses affecting the order of evaluation.
The arith-eval
function should take as an argument a string with the expression to evaluate, and return an integer number as its result. The function should be placed in a name space called final
.
Unit tests:
(deftest test-arith-eval (is (= 0 (arith-eval "0"))) (is (= 4 (arith-eval "2+2"))) (is (= 0 (arith-eval "2-2"))) (is (= 8 (arith-eval "2*4"))) (is (= 3 (arith-eval "1*2+1"))) (is (= -2 (arith-eval "1-2*2"))) (is (= 4 (arith-eval "(2+2)"))) (is (= 8 (arith-eval "(2+(2))*(1+((1)))"))) (is (= 431 (arith-eval "1+2*3+4-5*6+7*8-9"))) (is (= 12 (arith-eval "1+((2*3)+4-(5*6)+7)*(8-9)"))))
Using the Online Assignment Delivery System (SETA), deliver a single file called final.clj
containing the problem solution and the unit tests. No assignments will be accepted through e-mail or any other means.
IMPORTANT: The program source file must include at the top the authors' personal information (name and student id) within comments. For example:
;;; ITESM CEM, May 7, 2012. ;;; Clojure Source File ;;; Final Project: Arithmetic Evaluation ;;; 1166611 Jane Foster . . (The rest of the program goes here) .
Due date: Monday, May 7, 9:00 a.m.
This activity will be evaluated using the following criteria:
-10 | The program doesn't contain within comments the authors' personal information. |
---|---|
10 | The program contains syntax errors. |
DA | The program was plagiarized. |
20-50 | The program doesn't work, but it seams that some significant amount of time was spent in it. |
60-90 | The program works, but has some flaws. |
100 | The program works as requested. |