From: Pascal Bourguignon <pjb@in...>  20070122 13:10:19

Hans3 writes: > Im a LISP beginner and I would like some help. > I have 2 problems that might be easy for an advanced programmer: Since this is not specific to clisp, but to Common Lisp, a better forum would be news:comp.lang.lisp =20 > 1. A function which will interpolate the values of 2 lists in a number = of > steps, so '(1 1 1 1 1) and '(0.5 1 1.5 2 3) would become: > ( 1.000 1.000 1.000 1.000 1.000 > 0.875 1.000 1.125 1.250 1.500 > 0.750 1.000 1.250 1.500 2.000 > 0.625 1.000 1.375 1.750 2.500 > 0.500 1.000 1.500 2.000 3.000 ) >=20 > How do I make this? Good question. How do YOU do this? =20 You've got three parameters, a from list, a to list, and a number of steps. So you should write a function: (defun interpolate (fromlist tolist numberofsteps) ...) ; fill in the ellipsis. What did you do to get the above example result?=20 (or, if given by your teacher, how would YOU do it with:=20 (interpolate '(0 0 0 0) '(1 2 3 4) 6) ?) One hint: it would be easier/more natural to generate interpolations "line by line": (interpolate '(0 0) '(3 6) 4) > ((0 0) (1 2) (2 4) (3 6)) If you want the result under the form (0 0 1 2 2 4 3 6), you can always concatenate the resulting sublists in a final step. What we have here is a division of the problem in two easier parts. It's easy ton concatenate lists, and it's easy (or at least easier than the original problem) to generate the interpolations "line by line"). > 2. A function that returns a list containing integers between sets of l= ower > and upper boundaries. For example: function 20 26 23 28 would return: > (20 21 22 23 24 25 26 27 28) > Any even number should be possible. Basically, the answer is the same;. How would YOU do it? How can you divide the problem in simplier subproblems? > 3. A random generator that chooses values form a list or a stackpile wi= thout > repeating any values until all have been used once. Idem. Do you really need to write a random generator (it's hard to do in computers). You could write a pseudorandom generator, but is it what's asked? (There is already a pseudo random generator function in Common Lisp). Perhaps what's asked is only to return the values from the stackpile in a random order? What we have here, is that you'd better know your programming language (and libraries), to be able to use existing operators to your purposes. (And also, becareful with specifications, they are often not precise enough and misleading). =20 > 4. A random generator that chooses values form a list or a stackpile wi= th a > specific weight. Example: (weight '(1 2 3) '(4 2 1)) means that 1 has a > weight of 4, 2 has a weight of 2 and 3 has a weight of 1, so 1 will be = twice > as much in a list that 2 and so on. Idem. =20 Hint: if you have a (pseudo) random generator giving integers between 0 and N1 inclusive in equiprobability, how do you map these integers to a set of N elements to keep the equiprobability? And would you map these N integers to another set of elements to get different probabilities? > I would grately appreciate if anyone could tell me how to do this, so I= can > figure out the rest I want to do. Please help me out! >=20 > Thanks, Hans =20 __Pascal Bourguignon__ http://www.informatimago.com/ READ THIS BEFORE OPENING PACKAGE: According to certain suggested versions of the Grand Unified Theory, the primary particles constituting this product may decay to nothingness within the next four hundred million years. 