Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #415: Maintenance window broken


comp / comp.lang.lisp / Re: (3-digit combination) Lock.lsp (in Gauche Scheme)

SubjectAuthor
* (3-digit combination) Lock.lsp (in Gauche Scheme)HenHanna
+* Re: (3-digit combination) Lock.lsp (in Gauche Scheme)HenHanna
|`* Re: (3-digit combination) Lock.lsp (in Gauche Scheme)HenHanna
| +- Re: (3-digit combination) Lock.lsp (in Gauche Scheme)Paul Rubin
| `- Re: (3-digit combination) Lock.lsp (in Gauche Scheme)HenHanna
`* Re: (3-digit combination) Lock.lsp (in Gauche Scheme)Paul Rubin
 `* Re: (3-digit combination) Lock.lsp (in Gauche Scheme)HenHanna
  `- Re: (3-digit combination) Lock.lsp (in Gauche Scheme)Paul Rubin

1
Subject: (3-digit combination) Lock.lsp (in Gauche Scheme)
From: HenHanna
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Mon, 26 Feb 2024 11:47 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@gmail.com (HenHanna)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: (3-digit combination) Lock.lsp (in Gauche Scheme)
Date: Mon, 26 Feb 2024 03:47:28 -0800
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <urhtof$2grs4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 26 Feb 2024 11:47:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2a69445d6b08e3756b6d877d3cc6915a";
logging-data="2649988"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19K5EN0Ik89j3cDMldb2J/B9R5fGq2y4sg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Km7Xu18iPej9egedPqOPL8Te/Ec=
Content-Language: en-US
View all headers

(pls suggest improvements. Thanks!)

PS C:\Lisp\LockPuz> gosh -I .
gosh> (load "Lock.lsp")
1000 ( Now applying Constraint: ) ((6 8 2) (1 1))
192 ( Now applying Constraint: ) ((6 1 4) (1 0))
38 ( Now applying Constraint: ) ((2 0 6) (2 0))
1
((0 4 2))

(define (Score X Y)
(list (apply + (map (lambda (y) (if (member y X) 1 0)) Y))
(count zero? (map - X Y))))

(define (MapCan f Lis) (apply append (map f Lis)))

(define (run)
(let* ((Const '(((6 8 2) (1 1))
((6 1 4) (1 0))
((2 0 6) (2 0)) ))
(dig (iota 10))
(Cand (MapCan (lambda (x)
(map (lambda (i) (cons x i))
(MapCan (lambda (y) (map (lambda (z) (list y z))
dig)) dig))) dig)))
(dolist (req Const)
(format #t "~T ~S ~T ( Now applying Constraint: ) ~T ~S ~%"
(length Cand) req)
(set! Cand
(filter (lambda (c) (equal? (Score c (car req)) (cadr req)))
Cand)))
(format #t "~T ~S ~% ~T ~S ~%" (length Cand) Cand)))
(run)

Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
From: HenHanna
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Mon, 26 Feb 2024 12:23 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@gmail.com (HenHanna)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
Date: Mon, 26 Feb 2024 04:23:14 -0800
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <urhvri$2grs4$2@dont-email.me>
References: <urhtof$2grs4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 26 Feb 2024 12:23:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2a69445d6b08e3756b6d877d3cc6915a";
logging-data="2649988"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7g47dKXKEsHDwren8VIcxaOkBCDkNtG0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:vgtVSJuyJ7p7gSDKHL9mgAOybJE=
In-Reply-To: <urhtof$2grs4$1@dont-email.me>
Content-Language: en-US
View all headers

On 2/26/2024 3:47 AM, HenHanna wrote:
>                  (pls suggest improvements.  Thanks!)
>
>
> PS C:\Lisp\LockPuz>        gosh    -I   .
> gosh> (load "Lock.lsp")
>          1000    ( Now applying Constraint: )        ((6 8 2) (1 1))
>          192     ( Now applying Constraint: )        ((6 1 4) (1 0))
>          38      ( Now applying Constraint: )        ((2 0 6) (2 0))
>          1
>          ((0 4 2))
>
>
> (define (Score X Y)
>   (list (apply + (map (lambda (y) (if (member y X) 1 0))    Y))
>         (count zero?  (map - X Y))))
>
> (define (MapCan f Lis)    (apply append (map f Lis)))
>
> (define (run)
>   (let* ((Const '(((6 8 2)  (1 1))
>                   ((6 1 4)  (1 0))
>                   ((2 0 6)  (2 0)) ))
>          (dig (iota 10))

>          (Cand (MapCan (lambda (x)
>                    (map (lambda (i) (cons x i))
>                         (MapCan (lambda (y) (map (lambda (z) (list y z))
>                                                  dig)) dig))) dig)))

more readable as:

(define (conv3 x)
(list (floor/ x 100) (mod (floor/ x 10) 10) (mod x 10)))

(define Thousand (map conv3 (iota 1000)))

Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
From: HenHanna
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: novaBBS
Date: Fri, 1 Mar 2024 02:11 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: HenHanna@dev.null (HenHanna)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
Date: Fri, 1 Mar 2024 02:11:33 +0000
Organization: novaBBS
Message-ID: <58c90d8377ad4b964e3d2f7b53b2c8cf@www.novabbs.com>
References: <urhtof$2grs4$1@dont-email.me> <urhvri$2grs4$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="406180"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 5a1f1f09909a70d7ae18ae9af00e018f83ece577
X-Rslight-Site: $2y$10$nIrgEeS1KX6ll7H2485Dq.OTdRJ7m3QHuHBW3kyjhAAXZCp3EsYxK
X-Spam-Checker-Version: SpamAssassin 4.0.0
View all headers

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

Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
From: Paul Rubin
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Fri, 1 Mar 2024 02:28 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
Date: Thu, 29 Feb 2024 18:28:44 -0800
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <87plweelcz.fsf@nightsong.com>
References: <urhtof$2grs4$1@dont-email.me> <urhvri$2grs4$2@dont-email.me>
<58c90d8377ad4b964e3d2f7b53b2c8cf@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="943bcaa197a75ee88da3147cd0703006";
logging-data="970899"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/z33/ow2b3C5FFirKFzbiv"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:8VLhLhuH1+o5eRlsPFMuEptIQGc=
sha1:bU9iDEcg/D/qIUGk/Cq2w2ofGaU=
View all headers

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:

(define (score2 candidate answer)
(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.

Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
From: HenHanna
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: novaBBS
Date: Fri, 1 Mar 2024 02:56 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: HenHanna@dev.null (HenHanna)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
Date: Fri, 1 Mar 2024 02:56:20 +0000
Organization: novaBBS
Message-ID: <013ce1d7ab085542c811d464cb6c3536@www.novabbs.com>
References: <urhtof$2grs4$1@dont-email.me> <urhvri$2grs4$2@dont-email.me> <58c90d8377ad4b964e3d2f7b53b2c8cf@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="408831"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$PfB0RBF.2TXpWF8FI7.wxus4vL5gBrdLBtre/dASLWjOjUXedsLci
X-Rslight-Posting-User: 5a1f1f09909a70d7ae18ae9af00e018f83ece577
X-Spam-Checker-Version: SpamAssassin 4.0.0
View all headers

(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

Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
From: Paul Rubin
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Fri, 1 Mar 2024 03:39 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
Date: Thu, 29 Feb 2024 19:39:06 -0800
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <87h6hqei3p.fsf@nightsong.com>
References: <urhtof$2grs4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="943bcaa197a75ee88da3147cd0703006";
logging-data="1116582"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185hCI2JFsb2mpSvw5xdIrH"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:A4tCVmIbq/jfV5Wqi6ZuSRIXfEQ=
sha1:/P9YTImXfKCnzyRtz06sfLvZY4I=
View all headers

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

Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
From: HenHanna
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: novaBBS
Date: Sat, 2 Mar 2024 09:40 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.mixmin.net!news.neodome.net!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: HenHanna@dev.null (HenHanna)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
Date: Sat, 2 Mar 2024 09:40:04 +0000
Organization: novaBBS
Message-ID: <58a6bc89dcf829f6041d052ec4bd8bb4@www.novabbs.com>
References: <urhtof$2grs4$1@dont-email.me> <87h6hqei3p.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="556247"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$c2iO.9u/ROWzp6xEJ31VtuunLNN6HDUmn2HcC2mUe1B.JYKCXmx/W
X-Rslight-Posting-User: 5a1f1f09909a70d7ae18ae9af00e018f83ece577
X-Face: P#KeQ)CUdd!==@fw~Ms1=,Hb`IWtb6:Mw)x3B=H1BfNC\lz?Nb&)M9}$>?'X7l;CuB}utlJ=PHsRBSG6X>dYZ$[>P]$~+`>@V6$t}hTLoQ7XC~W\>:`B3ALU]SH;d(\MEc}znW8m}-ma&yPFkJ2@KSQrz=!Y;><;6a>z6N+mt`ClCt.PAE<o+B$qjwejZSZ,w]^;vrdl24z5(pm={l,F10qRDF
X-Spam-Checker-Version: SpamAssassin 4.0.0
View all headers

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.

Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
From: Paul Rubin
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sat, 2 Mar 2024 18:44 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: (3-digit combination) Lock.lsp (in Gauche Scheme)
Date: Sat, 02 Mar 2024 10:44:28 -0800
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <87msrgeann.fsf@nightsong.com>
References: <urhtof$2grs4$1@dont-email.me> <87h6hqei3p.fsf@nightsong.com>
<58a6bc89dcf829f6041d052ec4bd8bb4@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="eae62830b098b966b50aa8923f159337";
logging-data="2128220"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183eF1WmTC2VJFoIRJ7wARi"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:HVp7Pz93eEARH1gjMtR3ZiL6wrA=
sha1:CUpAUNG+yVzJ/QyjL7+c6Fzu7Tk=
View all headers

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

1

rocksolid light 0.9.8
clearnet tor