Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

retrieving a specific row from array in LISP

56 views
Skip to first unread message

rahul...@gmail.com

unread,
Apr 7, 2008, 7:21:05 PM4/7/08
to
If we have following array
(setf *possible-die-combinations* (make-array '(20 6)
:initial-contents
'((1 3 2 4 5 6)
(1 2 4 5 3 6)
(1 4 5 3 2 6)
(1 5 3 2 4 6)
(2 3 6 4 1 5)
(2 6 4 1 3 5)
(2 4 1 3 6 5)
(2 1 3 6 4 5)
(3 5 6 2 1 4)
(3 6 2 1 5 4)
(3 2 1 5 6 4)
(3 1 5 6 2 4)
(4 6 5 1 2 3)
(4 5 1 2 6 3)
(4 1 2 6 5 3)
(4 2 6 5 1 3)
(5 3 1 4 6 2)
(5 1 4 6 3 2)
(5 4 6 3 1 2)
(5 6 3 1 4 2))))

If you would notice, in every row the set of first and second elements
together is unique. For e.g. the first row has (1, 3) and the second
row has (1, 2).
Now I want to retrieve a specific row based on this given combination
of first and second element. How do I do it?

Pascal J. Bourguignon

unread,
Feb 10, 2009, 8:12:44 AM2/10/09
to
rahul...@gmail.com writes:

How do you do it?


(let ((f 1)
(s 4))
(find-if (lambda (row) (and (equal f (first row)) (equal s (second row))))
*possible-die-combinations*))

--
__Pascal Bourguignon__

0 new messages