• #### Re: (3-digit combination) Lock.lsp (in Gauche Scheme)

From Paul Rubin@21:1/5 to HenHanna on Thu Feb 29 18:28:44 2024
XPost: comp.lang.scheme

HenHanna <HenHanna@dev.null> writes:

(define (Score X Y)
(list (count list? (map (lambda (y) (member y X)) Y))
(count zero? (map - X Y))))
; <--- Is there a better way? (using equal? instead of - ) ?

This was my version:

(let* ((well-placed (length (filter identity (map = candidate answer))))
(wrongly-placed (- (length (lset-intersection = candidate answer))
well-placed)))
(values well-placed wrongly-placed)))

Maybe there is something better.

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From HenHanna@21:1/5 to All on Fri Mar 1 02:56:20 2024
XPost: comp.lang.scheme

(define (Score X Y)
(list (count (lambda (y) (member y X)) Y)
(count equal? X Y)))

Where can i find doc for COUNT ?

The section in the Gauche manual is so short!

but now i see that it explains what i was looking for
> the count of times pred returned true is returned.

https://practical-scheme.net/gauche/man/gauche-refe/Pairs-and-lists.html

Function: count pred clist1 clist2 …

[R7RS list] A procedure pred is applied to the n-th element of given lists, from n is zero to the length of the the shortest finite list in the given lists, and the count of times pred returned true is returned.

(count even? '(3 1 4 1 5 9 2 5 6)) ⇒ 3
(count < '(1 2 4 8) '(2 4 6 8 10 12 14 16)) ⇒ 3

At least one of the argument lists must be finite:

(count < '(3 1 4 1) (circular-list 1 10)) ⇒ 2

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From HenHanna@21:1/5 to All on Fri Mar 1 02:11:33 2024
XPost: comp.lang.scheme

i enjoyed working on the problem of coming up with a 1-line Python code.
We dont really have LINES in Lisp-Scheme... What would be a similar challenge in Lisp-Scheme?

(define (Score X Y)
(list (count list? (map (lambda (y) (member y X)) Y))
(count zero? (map - X Y))))
; <--- Is there a better way? (using equal? instead of - ) ?

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From Paul Rubin@21:1/5 to All on Thu Feb 29 19:39:06 2024
XPost: comp.lang.scheme

FYI, here is an interesting paper about playing Mastermind using a SAT
solver, beating other approaches. Mastermind turns out to be well-known
to be NP-complete (a quick web search found that).

https://www.seas.upenn.edu/~ncollina/Mastermind.pdf

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From HenHanna@21:1/5 to Paul Rubin on Sat Mar 2 09:40:04 2024
XPost: comp.lang.scheme

Paul Rubin wrote:

FYI, here is an interesting paper about playing Mastermind using a SAT solver, beating other approaches. Mastermind turns out to be well-known
to be NP-complete (a quick web search found that). https://www.seas.upenn.edu/~ncollina/Mastermind.pdf

thank you... i'll take a look.

What are some relevant sections in Knuth's book [Satisfiability] ?

Sudoku is mentioned several times, but not Mastermind.

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From Paul Rubin@21:1/5 to HenHanna on Sat Mar 2 10:44:28 2024
XPost: comp.lang.scheme

HenHanna <HenHanna@dev.null> writes:
What are some relevant sections in Knuth's book [Satisfiability] ?

That book discusses the algorithms used in SAT solvers, but from what
little I know, they are all tweaks and improvements on the DPLL
algorithm from the 1960s:

https://en.wikipedia.org/wiki/DPLL_algorithm

Thus, if you want to study the workings of SAT solvers, you could start
by looking at MiniSAT which is one of the simplest. If you want to
learn how to use them, this is good:

https://yurichev.com/writings/SAT_SMT_by_example.pdf

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)