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
CLISP
-
- Posts: 78
- Joined: Mon Dec 01, 2014 12:29 pm
- Contact:
Re: CLISP
(2 3 3) isn't a pair. You mean any list of numbers?
-
- Posts: 2
- Joined: Sat Nov 05, 2016 10:43 pm
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).
.
.
-
- Posts: 166
- Joined: Sun Nov 28, 2010 4:21 pm
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.
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.