Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The source code in R5RS (Scheme) Write a function, great-lcm , in Scheme that takes a list of two or more positive integers (duplicates are

The source code in R5RS (Scheme)

Write a function, great-lcm, in Scheme that takes a list of two or more positive integers (duplicates are possible and zero not included) and other auxiliary parameters of your choice. The list L is flat, i.e., it does not contain sublists. The function great-lcm returns the greatest least common multiple of all possible partitions of L. The least common multiple of a partition is defined as the least common multiple of the sums of the two subsets of a partition. You only need to return the greatest lcm.

It is up to you to choose the auxiliary parameters that great-lcm takes. All auxiliary parameters must be numeric (not lists or any other types) and should have initial values set to 0. For example, if the list is (1 2 3) and you decide to use two additional auxiliary parameters, great-lcm should be called as follows:

(great-lcm (1 2 3) 0 0)

If there are three auxiliary parameters, then it must be called:

(great-lcm (1 2 3) 0 0 0)

Examples:

(2 3 4) returns 20. All possible paritions are: {2, 3} and {4} with lcm(2 + 3, 4) = 20; {2, 4} and {3} with lcm(2 + 4, 3) = 6; {3, 4} and {2} with lcm(3 + 4, 2) = 14. The greatest of all possible partitions is 20.

(2 3 3) returns 15. The partition with the greatest lcm is {2 3}, with sum 5, and {3}, with sum 3.

(6 1 4 2 3) returns 63. A partition with the greatest lcm include {3 4}, with sum 7, and {1 2 6}, with sum 9.

(23 37 12 43) returns 3234. A partition with the greatest lcm include {12 37} with sum 49, and {23 43} with sum 66.

(30 1 40 2) returns 1320. A partition with the greatest lcm include {40} and {1 2 30}.

The whole solution must be packed in one recursive function, great-lcm, which must look as follows

(define great-lcm (lambda () (cond Your logic here )))

In other words, you must choose your auxiliary parameters and define ONE COND statement.

Inside COND, you can use ONLY the following constructs:

null?

car

cdr

else

lcm (A function in scheme that calculates the lcm of numbers)

+

>

great-lcm

if

user defined name (for the names of your parameters)

integer literals

parenthesis

You cannot use a construct if it is not listed above. The use of built-in functions is not allowed if it is not listed above, either. You may not write additional functions. Only great-lcm must be defined

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

Have you ever had a spiritual experience?

Answered: 1 week ago

Question

1. Television more Over watching faceing of many problems ?

Answered: 1 week ago

Question

Is there a link between chronic stress and memory function?

Answered: 1 week ago