Question
Source code must be written in R5RS! Write a function two-subsets in Scheme that takes a list L of positive integers (duplicates are possible, zero
Source code must be written in R5RS!
Write a function two-subsets in Scheme that takes a list L of positive integers (duplicates are possible, zero is not considered a positive integer) and some auxiliary parameters of your choice. The function two-subsets returns #t if the list L contains two subsets with equal sums of elements and with equal numbers of elements. Otherwise (if two subsets satisfying the condition above do not exist), the function returns #f. Assume that the list L contains at least two integers.
It is up to you to choose the auxiliary parameters that two-subsets takes. All auxiliary parameters must be numeric (not lists) and should have initial values set to zero. For example, if L is (1 2 3) and if you decide to use two additional auxiliary parameters, then two-subsets must be called as follows:
(two-subsets '(1 2 3) 0 0)
If there are three auxiliary parameters, then the function must be called: (two-subsets '(1 2 3) 0 0 0) and so on.
Examples:
(two-subsets '(7 7) 0 0) returns #t. The two subsets are {7} and {7}.
(two-subsets '(5 3 2 4) 0 0) returns #t. The two subsets are {2, 5} and {3, 4}.
(two-subsets '(1 2 3 6 9) 0 0) returns #f.
The whole solution must be packed in one recursive function two-subsets which must look as follows:
(define two-subsets (lambda ( of your choice initially set to zero>) (cond ... ))) In other words, you have to choose your auxiliary parameters and define a COND statement. Nested COND statements are allowed. Inside COND, you can use ONLY the following constructs: -null? -cond -car -cdr -else -+ -= - not - and - #t - #f - two-subsets - the names of your parameters, such as list, sum, etc. - numeric constants, such as 0, 1, 2, etc. - parentheses You cannot use a construct if it is not listed above. In other words, your code must define and use only one function, two-subsets, which must be defined using the template and the constructs listed above. The use of built-in functions is not allowed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started