#87
Create an Equation
 

Difficulty:N/A
Topics:hard code-generation


Write a function which takes three or more integers. Using these integers, your function should generate clojure code representing an equation. The following rules for the equation must be satisfied: 1. All integers must be used once and only once. 2. The order of the integers must be maintained when reading the equation left-to-right. 3. The only functions you may use are +, *, or =. 4. The equation must use the minimum number of parentheses. 5. If no satisfying equation exists, return nil.
test not run
(= (__ 3 4 7) '(= (+ 3 4) 7))
test not run
(= (__ 3 4 12) '(= (* 3 4) 12))
test not run
(= (__ 3 4 14) nil)
test not run
(= (__ 3 4 5 35) '(= (* (+ 3 4) 5) 35))
test not run
(= (__ 3 4 5 60) '(= (+ (* 3 4) 5) 60))
test not run
(= (__ 3 4 5 23) '(= (+ 3 (* 4 5)) 23))
test not run
(= (__ 3 4 5 27) '(= (* 3 (+ 4 5)) 27))
test not run
(= (__ 3 4 5 6) nil)
test not run
(= (__ 1 2 10 100 2001) '(= (+ 1 (* 2 10 100)) 2001)
test not run
(= (__ 1 2 10 100 1300) '(= (* (+ 1 2 10) 100) 1300)


Code which fills in the blank: