Re: (3-digit combination) was:

Liste des GroupesRevenir à cl lisp 
Sujet : Re: (3-digit combination) was:
De : enometh (at) *nospam* meer.net (Madhu)
Groupes : comp.lang.lisp
Date : 11. Mar 2024, 04:09:35
Autres entêtes
Organisation : Motzarella
Message-ID : <m3cys1bjts.fsf@leonis4.robolove.meer.net>
References : 1 2 3 4 5 6 7
* Madhu <m3msr6brlo.fsf@leonis4.robolove.meer.net> :
Wrote on Sun, 10 Mar 2024 10:39:23 +0530:

* Lawrence D'Oliveiro <usjehr$2pu3d$1@dont-email.me> :
Wrote on Sun, 10 Mar 2024 04:56:28 -0000 (UTC):
On Sun, 10 Mar 2024 09:49:15 +0530, Madhu wrote:
also this produces 2 results (0 6 2) and (0 4 2) -- the (0 4 2) result
wasn't reported in the solutions in the other languages, is it wrong?
(and therefore my whole approach)?
>
You wanted to talk about “dicksizing” ... I would say your approach is
overly long on code, and comes up short on correctness.
>
Well I can't see it.  Maybe it is a shortcoming in the other approaches
that misses this solution.
>
does "0 4 2" violate any the rules posted in the original picture?

As Paul Rubin pointed out in a parallel post (Thanks!), it is
not (0 4 2) but (0 6 2) which is wrong, and it violates the 3rd
constraint in the problem

 --- (206): Two numbers are correct but wrongly placed

In the notation suggested in my first post i expressed this constraint
as

(defvar $c3
  (ONE-OF (ONE-OF '#?(.20) '#?(02.) '#?(0.2)) ;; 2 & 0 are correct
  (ONE-OF '#?(62.) '#?(6.2) '#?(.62)) ;; 2 & 6 are correct
  (ONE-OF '#?(06.) '#?(6.0) '#?(.60)) ;; 0 & 6 are correct
  ))

Which is incomplete because the rule indicates 2 numbers are incorrectly
placed, the third is not placed at all.

. Instead it should look like

  (ONE-OF (ONE-OF '#?([^6]20) '#?(02[^6]) '#?(0[^6]2)) ;; 2 & 0 are correct
  (ONE-OF '#?(62[^0]) '#?(6[^0]2) '#?([^0]62)) ;; 2 & 6 are correct
  (ONE-OF '#?(06[^2]) '#?(6[^2]0) '#?([^2]60)) ;; 0 & 6 are correct
  ))

the function GET-WRONGLY-PLACED (which is used in generating the
constraint) can be fixed to look like this:

```
(defun get-wrongly-placed (list indices &aux (always-excludes
      (loop for i below (length list)
    unless (find i indices)
    collect (elt list i))))
  ;; elements of list at positions in indices are incorrectly placed
  `(or ,@(loop for idx in (get-permutations (loop for i below (length list) collect i)
    (length indices))
       unless (loop for i in idx for j in indices
    thereis (= i j))
       collect
       `(and ,@(loop for i in idx for j in indices
     collect (make-eql-clause (elt list j) i))
     ,@(loop for j below (length list)
     unless (find j idx)
     collect `(not (or ,@(loop for x in always-excludes
       collect (make-eql-clause x j)))))))))
```

Untested on problems with larger number of variables.

I think I realised this sending after my first post (and even fixed it
but the changes got lost and I forgot about it for my second post), but
yes the posted code was short on correcteness

Date Sujet#  Auteur
10 Mar 24 * Re: (3-digit combination) was:5Madhu
10 Mar 24 +* Re: (3-digit combination) was:3Lawrence D'Oliveiro
10 Mar 24 i`* Re: (3-digit combination) was:2Madhu
11 Mar 24 i `- Re: (3-digit combination) was:1Madhu
10 Mar 24 `- Re: (3-digit combination) was:1Paul Rubin

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal