Write a function two-subsets in scheme that takes a list l

Assignment Help Programming Languages
Reference no: EM131482794

Online Programming Languages Assignment

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.

Note the difference from HW2: here, it is not required that the whole list be split into two subsets. In HW3, some elements of the list could be left out from the two subsets. Therefore, every list, which is a solution to HW2 is also be a solution to HW3. However, there are solutions to HW3 that are not solutions to HW2.

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.

Note that the function must be called two-subsets. Other names will not be accepted. The list must precede the auxiliary parameters, which are initially set to zeroes.

There is no need to optimize your code. Try to come up with a working solution.

Examples (for the sake of illustration, two auxiliary parameters are used):

(two-subsets '(7 7) 0 0) returns #t. The two subsets are {7} and {7}.
(two-subsets '(7 7 1) 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 '(5 3 21 2 4) 0 0) returns #t. The two subsets are {2, 5} and {3, 4}.
(two-subsets '(2 13 7 5 16 11) 0 0) returns #t. The two subsets are {7, 11} and
{5, 13}.
(two-subsets '(1 2 3 6 9) 0 0) returns #f.
(two-subsets '(10 4 7 102 36 6 17 54) 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 (<list L followed by numeric parameters 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.

If your program uses a construct not on the list, then it is not a solution to the homework.

It is not allowed to bypass the homework requirements by packing several functions in one function definition using a numeric flag. In other words, for one value of the numeric flag the function does one thing and for other value of the flag the function does something else.

Here is an example of packing several function using a numeric flag as a second parameter:

(define two-subsets (lambda (list flag) (cond

((= flag 0) the function implements one type of functionality) ((= flag 1) the function implements a second type of functionality) (else the function implements a third type of functionality )

)))

Here, we have three functions (corresponding to flag values of 0, 1, and 2) packed in one COND statement. The flag is not related to the problem at hand and it used for the sole purpose of packing different functionalities in one COND statement. This is not allowed.

Reference no: EM131482794

Questions Cloud

Performance to generate a total revenue : A 6000- seat theater has tickets for sale at $27 and $40. How many tickets should be sold at each price for a sellout performance to generate a total revenue.
Why people feel that life was better in an earlier time : Gregg Easterbrook, in his book, The Progress Paradox (New York: Random House, 2003) noted that life in the United States is significantly better today.
Famous ancient roman structures : Select one (1) of the following famous ancient Roman structures that you find most fascinating: Colosseum, Circus Maximus, Pantheon, insulae, or bath complexes.
Play football and michael does not play basketball : Let p represent the statement "Jim plays football", and let q represent the statement "Michael plays basketball". Convert the following compound statement.
Write a function two-subsets in scheme that takes a list l : Write a function two-subsets in Scheme that takes a list L of positive integers and some auxiliary parameters of your choice.
Certificate of deposit : The amount in the bank account is_____ the amount in the bonds is _____ and the amount in the certificate of deposit is ____
Solve the given case according to given information : In 2001 Nobel Prize winner Robert Solow noted that "the computer age is seen everywhere except in productivity data." More recent studies suggest that it takes.
Topic - advantages and disadvantages of cloud computing : Write Literature Review on given topic. Topic: Advantages and Disadvantages of Cloud Computing
How much was he charged for each shirt : How much was he charged for each shirt, each pair of slack, and each sports coat?

Reviews

Write a Review

Programming Languages Questions & Answers

  Design program to accepts account number

Design a program that accepts an account number, the account owner's first and last names, and a balance. Print the projected running total balance for each year for the next 20 years.

  Define a virtual terminal emulation window

NETW240: Managing User and Group Accounts, Using the mouse, click on the Fedora icon. Select ‘System Tools' and then select ‘Terminal'. A virtual terminal emulation window will appear. The window will provide access to the shell command-line prompt..

  Create an example of a nested if structure

Create an example of a nested IF structure and build it into a small project. Compile and execute the program, and discuss any challenges you encountered. Post the code of the program

  Calculates how much an employee would earn over a period

Write a program that calculates how much an employee would earn over a period of time (in months), if, every month, the employee' pay-per-hour rate is one dollar more than the month before.

  Write a program learn multiplication

Write a program which will help the elementary school student learn multiplication. Use Random object to produce two positive one-digit integers.

  Write a program which reads a string as an input

Write a program which reads a string as an input then it counts number of occurrences for each letter, and then displays the letters which occurred 3 times or more.

  Prepare calculator application - mock objects for testing

Which other classes do you think will need to be stubbed with mock objects for testing the application? For each class you identify explain why you think that class needs mocking and at least three di erent mocked behaviours you will need.

  Write program using to take input two integers by while loop

Write a program which uses while loops to perform following steps: Prompts user to input two integers: firstNum and secondNum. (firstNum must be less than secondNum).

  Creating class savingsaccount using static variable

Create class SavingsAccount. Use static variable annualInterestRate to store annual interest rate for all account holders.

  Write program that calculate and prints the monthly paycheck

Write a program that calculates and prints the monthly paycheck for an employee. The net pay is calculated after taking the following deductions: Federal Income Tax: 15%.

  Electro-magnetic force in newtons

The topic of this assignment was chosen so that you won't allow mathematical equations and scientific notation to intimidate you. No knowledge is required to complete the assignment beyond knowing how to perform mathematical operations within a fo..

  Develop a program to input miles driven and gallons for tank

Develop a program in C++ that will input the miles driven and gallons used (both as integers) for each tankful. The program should calculate and display the miles per gallon obtained for each tankful.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd