문제

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 DOLISTs?

도움이 되었습니까?

해결책

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))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top