My problem is to make a simple plus-minus program using Racket R5RS language. The basic idea of the problem is to put plus/minus signs in front of every element in list and check if the result is one of the elements in list. Below is what I have right now:
(define plus-minus (lambda (lst l sum)
(cond
((null? lst)
(cond
((null? l) #f)
((= sum (car l)) #t)
(else (plus-minus lst (cdr l) sum))))
((plus-minus (cdr lst) l (+ sum (car lst))) #t)
((plus-minus (cdr lst) l (- sum (car lst))) #t)
(else #f))))
This code is working, but it is required that there should be one and only one list in the parameters and all others are numbers. The first two parameters in my code are identical when the function is firstly called. The first one is the one to get the sum. The second one is to check if sum equals one of the elements in list. Both of the lists are required because as I get the sum, the elements in the first list are removed.
My question is, how to get rid of the second list in parameters? Is there anyway I can iterate through the list without removing elements (CDR commend)?