common lisp - using CLISP to make equations given a sequence of numbers -
common lisp - using CLISP to make equations given a sequence of numbers -
so have utilize clisp create 2 equaline equations given sequence of numbers
ie user enters 2 2 2 2:
2 + 2 = 2 + 2 ; valid
2 - 2 = 2 - 2 ; valid
2 = 2 + 2 - 2 ; valid
2 + 2 + 2 = 2 ; not valid
user enters 6 2 2 2:
6 = 2 + 2 + 2 ; valid
6 = 2 * 2 + 2 ; valid
6 + 2 = 2 * 2 ; not valid
the operates of *, /, +, , - used basic math, , = signify left hand side = right hand side.
my problem lies in lack of real lisp training , start. think have utilize macros, i'm not sure how utilize macros or how macros used this.
i know have define function such
(defun findequation (a b c d))
but there i'm lost
first step: create combinations of relevant symbols, restriction 1 =
should present.
example input: (2 2 2 2)
, (+ - * / =)
example output: (2 + 2 + 2 = 2)
, (2 + 2 - 2 = 2)
, (2 - 2 - 2 = 2)
, …
second step: utilize shunting-yard algorithm transform infix list of alternating numbers , symbols tree.
example input: (2 + 2 = 2 - 2)
example output: (= (+ 2 2) (- 2 2))
then can evaluate see if true.
common-lisp
Comments
Post a Comment