On 2024-02-26, HenHanna <HenHanna@gmail.com> wrote:
>
>                   (i just wrote (non-elegant) Python code.)
>
>
> Could you share a short, VERY Readable Pythonic (or Common Lisp, Scheme) 
> code that solves this?

TXR Lisp, using scoring method:

(defun score (pat can)
  (vec (sum-each ((p pat) (c can))
         (if (eql p c) 1 0))
       (len (isec pat can))))

(defun filt-score (pat ngoodpl nbadpl list)
  (keep-if (op equal (score pat @1) (vec ngoodpl nbadpl)) list))

(flow "000".."999"
  list-seq
  (filt-score "682" 1 1)
  (filt-score "614" 0 1)
  (filt-score "206" 0 2)
  ;; surprises: these two not required
  (filt-score "738" 0 0)
  (filt-score "780" 0 1)
  prinl)

$ txr lock2.tl
("042")

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca