# Scheme (LISP) homework assignment, challenging puzzle

I know it's a long shot, but a good friend challenged me with his homework assignment for a Master's Level CS course. The program has to be written in SCHEME.

Here's the challenge:

-given a number, x, and a list of numbers, n...-determine whether or not the list, n, can be divided into 3 sublists such that the sum of each sublist is < x -and return t/f

These are the constraints:

> > -The solution has two functions or less

> > -No use of internal sort function

> > -There are not any limits on efficiency, the program can run for a long time

> >

I don't know much about scheme at all, but talking with my friend I think this is what we need to do something like this:

given all permutations of the list n

on each permutation

iterate through each element in the permutation, and sum the elements.

as long as the sum of the elements <=x, assign them to sublist[1] such that the sum of the elements in sublist[1] <= x.

when sublist[1]>=x, start a new sublist[2] and do the same thing meaning assign the remaining elements to sublist[2] such that the sum of the elements in sublist[2] <= x

when sublist[2]>=x, start a new sublist[3] and do the same thing meaning assign the remaining elements to sublist[3] such that the sum of the elements in sublist[3] <= x

if the sublist[3] >x then the permutation is not valid,

move on to the next permutation

if a permutation is valid, return true and exit the loop

I also think there's an opportunity for recursion in here somewhere.

Apologies for my pseudo-code. I know very little about fu

Acerca do Empregador:
( 28 comentários ) United States

ID do Projeto: #2966492

## 1 freelancer está oferecendo em média \$9 para esse trabalho

rosper

See private message.

\$8.5 USD em 1 dia
(0 Comentários)
0.0