The program must be written in R5RS Write a function named two in Scheme that takes a single parameter, a list of intege

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

The program must be written in R5RS Write a function named two in Scheme that takes a single parameter, a list of intege

Post by answerhappygod »

The program must be written in R5RS
Write a function named two in Scheme that
takes a single parameter, a list of integers. The function
two
returns #t if the list is built from no more than two
different integers. Otherwise, it returns #f. The
list L is flat, i.e., it does not contain sublists.
Note that the function must be called two and that it takes a
single parameter, a list. Functions
with other names or other parameters will not be graded.

Examples
(two ‘(7)) returns #t
(two ‘(7 7)) returns #t
(two ‘(6 7)) returns #t
(two ‘(1 2 2 2 1 1)) returns #t
(two ‘(21 15 15 21 15)) returns #t
(two ‘(5 7 5 6 5)) returns #f
(two ‘(10 15 21 22 10)) returns #f

The whole solution must be packed in one recursive function two
which must look as follows: (define two (lambda (list)
(cond
...
)))
In other words, you have to define a single COND statement. Nested
COND statements are not
allowed.
Inside COND, you can use ONLY the following constructs: -
null?
- car and cdr and their derivatives, cadr, cddr, etc.
- cons
- else
- =
- #t
- #f
- two
- list
- 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, which must be defined using the constructs
listed above. The use of built-
in functions is not allowed.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply