This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

CLISP

4 posts · 5065 views

Hey
I am beginner and just started to learn Clisp. Could someone please help me to create array of random integer number and find pair of numbers(from array) whose sum is equal to target number and also print their indices. Suppose if we create array of 10 number and target number is 8 then pair should be like (2 3 3), (4 4), (1 2 5), (8) with their indices
Thank you

Re: CLISP

(2 3 3) isn't a pair. You mean any list of numbers?

Re: CLISP

It is like if you generate 10 random number(5 8 7 2 3 5 2 6 8 1) then it should return all the subset whose sum is target number. If target number is 8 then it should return (8),(5 3),(7 1),(3 2 3),(1 5 2),(1 2 2 3).
.

Re: CLISP

The fact that you haven't even attemted this makes it sound like a homework assignment.

Building an array of random numbers will involve the symbols MAKE-ARRAY DOTIMES RANDOM AREF, and SETF.

Finding the sub-lists that sum to a total is a naturally recursive problem, your first step would be to sort the array.