I could figure out some way to do this myself but I have a feeling there's a simpler, perhaps built-in way to do this. I want to see if any two lists share an element. These are the two lists I'm dealing with at the moment:
((0 1 2) (3 4 5) (6 7 8) (0 3 6) (1 3 7) (2 4 8) (0 4 8) (2 4 6))
((0 1 7) (0 1 6) (0 1 3) (0 3 7) (0 3 6) (0 6 7) (1 3 7) (1 3 6) (1 6 7) (3 6 7))
Since both lists contain (1 3 7)
, I'd like a comparison of the lists to return T
.
Is there a better way to do this than just setting up a couple DOLIST
s?
How about INTERSECTION?
(defvar a '((0 1 2) (3 4 5) (6 7 8) (0 3 6) (1 3 7) (2 4 8) (0 4 8) (2 4 6)))
=> A
(defvar b '((0 1 7) (0 1 6) (0 1 3) (0 3 7) (0 3 6) (0 6 7) (1 3 7) (1 3 6) (1 6 7) (3 6 7)))
=> B
(intersection a b :test 'equal)
=> ((1 3 7) (0 3 6))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With