help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding repetitions of 8-tuples


From: Arthur Miller
Subject: Re: Finding repetitions of 8-tuples
Date: Sun, 01 Jan 2023 16:13:50 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Hans Lonsdale <hanslonsdale@mailfence.com> writes:

> I have 16 collections of 8 numbers
>
> (11 12 11 44 11 12 11 23)
> (12 21 11 44 11 12 11 23)
> and so on
>
> I want to find whether there are repetitions of each 8-tuple.
> The order in which the numbers occur is not important.

Have you looked at "lists as sets" chapter in the manual?

There is a 'cl-subsetp' you could start with:

  cl-subsetp is an autoloaded native-compiled Lisp function in ‘cl-seq.el’.

  (cl-subsetp LIST1 LIST2 [KEYWORD VALUE]...)

  Return true if LIST1 is a subset of LIST2.
  I.e., if every element of LIST1 also appears in LIST2.

  Keywords supported:  :test :test-not :key


(defvar l1 '(11 12 11 44 11 12 11 23))
(defvar l2 '(12 21 11 44 11 12 11 23))

(cl-subsetp l1 l2) ;; returns t

However there is a slight problem since it tests for the subset:

(defvar l3 '(12 21 11 44 11 12 11))

(cl-subsetp l3 l2) ;; returns t also

(and (cl-subsetp l3 l2)
     (= (length l3) (length l2))) ;; should do


Alternatively there functions to test membership, so you could easily roll your
own little defun with 'member' or something else.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]