CLISP

Discussion of Common Lisp

CLISP

Postby scjaiswal00 » Sat Nov 05, 2016 10:52 pm

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
scjaiswal00
 
Posts: 2
Joined: Sat Nov 05, 2016 10:43 pm

Re: CLISP

Postby David Mullen » Sun Nov 06, 2016 1:14 pm

(2 3 3) isn't a pair. You mean any list of numbers?
David Mullen
 
Posts: 63
Joined: Mon Dec 01, 2014 12:29 pm

Re: CLISP

Postby scjaiswal00 » Tue Nov 08, 2016 1:57 pm

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).
.
scjaiswal00
 
Posts: 2
Joined: Sat Nov 05, 2016 10:43 pm

Re: CLISP

Postby pjstirling » Tue Nov 08, 2016 4:35 pm

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.
pjstirling
 
Posts: 135
Joined: Sun Nov 28, 2010 4:21 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 1 guest