Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Parts that positively cannot be assembled in improper order will be.


devel / comp.lang.lisp / Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

SubjectAuthor
* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtLawrence D'Oliveiro
+* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtPaul Rubin
|+* Re: Parenthesis Pileup (was Re: (Mastermind) puzzle (with 3 digits) -- ...)Lawrence D'Oliveiro
||`- Re: Parenthesis Pileup (was Re: (Mastermind) puzzle (with 3 digits) -- ...)Kaz Kylheku
|`- Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtKaz Kylheku
`* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtPaul Rubin
 +- Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtPaul Rubin
 +* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtLawrence D'Oliveiro
 |`* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtPaul Rubin
 | `* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtLawrence D'Oliveiro
 |  +- Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtGeorge Neuner
 |  `* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtPaul Rubin
 |   `* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtLawrence D'Oliveiro
 |    +* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtPaul Rubin
 |    |`* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtLawrence D'Oliveiro
 |    | `* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtPaul Rubin
 |    |  `* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtLawrence D'Oliveiro
 |    |   `- Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtPaul Rubin
 |    `* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtKaz Kylheku
 |     `* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtNuno Silva
 |      +- Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtLawrence D'Oliveiro
 |      `* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtHenHanna
 |       `* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtLawrence D'Oliveiro
 |        `* Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtHenHanna
 |         `- Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtLawrence D'Oliveiro
 `- Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code SoughtAndreas Eder

Pages:12
Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<urjq6t$31cu6$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18040&group=comp.lang.lisp#18040

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code
Sought
Date: Tue, 27 Feb 2024 04:59:09 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 106
Message-ID: <urjq6t$31cu6$1@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 27 Feb 2024 04:59:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d339ad4b21c64d41c58c7c072f1b4d54";
logging-data="3191750"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iq6B2UlhptpMGH7MpG22Y"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:MUuxM8snqkG2mygf717Ncz9H6gE=
 by: Lawrence D'Oliv - Tue, 27 Feb 2024 04:59 UTC

On Sun, 25 Feb 2024 20:27:42 -0800, HenHanna wrote:

> Could you share a short, VERY Readable Pythonic (or Lisp, Scheme) code
> that solves this?

This is my answer after spending this afternoon learning Guile. Much
more wordy than the Python version I previously posted. Anybody know
how to do it better?

(import
(rnrs base)
(rnrs lists)
)

(define (range n)
; returns a list of integers from 0 up to n - 1 inclusive.
(letrec
(
(subrange
(lambda (n)
(cond
((>= n 0) (cons n (subrange (- n 1))))
(#t '())
) ; cond
) ; lambda
)
)
(reverse (subrange (- n 1)))
) ; let
) ; define

(define (score candidate answer)
(let
(
(in-right-place 0)
(in-wrong-place 0)
)
(for-each
(lambda (a)
(for-each
(lambda (b)
(when (eq? a b)
(set! in-wrong-place (+ in-wrong-place 1))
; might be in right place, fixed up below
) ; when
) ; lambda
answer
) ; for-each
) ; lambda
candidate
) ; for-each
(for-each
(lambda (a b)
(when (eq? a b)
(set! in-right-place (+ in-right-place 1))
(set! in-wrong-place (- in-wrong-place 1))
) ; when
) ; lambda
candidate
answer
) ; for-each
(list in-right-place in-wrong-place)
) ; let
) ; score

(define required-scores
'(
((6 8 2) (1 0))
((6 1 4) (0 1))
((2 0 6) (0 2))
((7 3 8) (0 0))
((7 8 0) (0 1))
)
)

(for-each
(lambda (n)
(let-values
(
((a b c answer) (values #f #f #f #f))
)
(set! a (div n 100))
(set! n (- n (* a 100)))
(set! b (div n 10))
(set! c (- n (* b 10)))
(set! answer (list a b c))
(when
(for-all
(lambda (candidate)
(let
(
(required-score (cadr candidate))
)
(set! candidate (car candidate))
(equal? (score candidate answer) required-score)
) ; let
) ; lambda
required-scores
) ; for-all
(display answer)
(display "\n")
) ; when
) ; let-values
) ; lambda
(range 1000)
) ; let

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<87le75emqn.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18041&group=comp.lang.lisp#18041

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Tue, 27 Feb 2024 11:22:08 -0800
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <87le75emqn.fsf@nightsong.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="91574d2575cac45da5d1f33a64b22cc2";
logging-data="3546858"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18irt6GUxgAynrEv0hmgpSm"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:208XYVM7RMl0i+Nkxjgqa9yMPhg=
sha1:fmayJ2FLnwvJMPXS5rADC078+rM=
 by: Paul Rubin - Tue, 27 Feb 2024 19:22 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> This is my answer after spending this afternoon learning Guile. Much
> more wordy than the Python version I previously posted. Anybody know
> how to do it better?

The following works for me as a fairly simple port of the concise Python
version to Guile. Note that the parenthesis style is pretty much
universal in Lisp and variants. Editors support it, and automatic paren
balancing in the editors keep them from getting too confusing.

If you want to understand Scheme, I suggest reading through SICP (click
the open access link at mitpress.mit.edu/sicp for a download). That
said, I'm not much of a Scheme user myself, so the below might have some
style issues.

I think by now, the methods introduced in Scheme have moved on to newer
languages like OCaml and then Haskell, so you might want to study those
instead. learnyouahaskell.com is a good start with Haskell.

================================================================

(use-modules (srfi srfi-1)
(srfi srfi-11))

(define clues '((682 1 0) (614 0 1) (206 0 2) (738 0 0) (780 0 1)))
(define (digits n)
(values (quotient n 100) (remainder (quotient n 10) 10) (remainder n 10)))
(define (count . args) (length (filter identity args)))

(define (score candidate answer)
(let-values (((a b c) (digits candidate))
((x y z) (digits answer)))
(let ((well-placed (count (= a x) (= b y) (= c z)))
(wrongly-placed (count (or (= a y) (= a z))
(or (= b x) (= b z))
(or (= c x) (= c y)))))
(values well-placed wrongly-placed))))

(define (test)
(let ((n 682) (a 1) (b 0))
(let-values (((well-placed wrongly-placed) (score n 042)))
(and (= a well-placed) (= b wrongly-placed)))))

(define (check candidate)
(define (check1 clue)
(let ((n (car clue))
(a (cadr clue))
(b (caddr clue)))
(let-values (((well-placed wrongly-placed) (score candidate n)))
(and (= a well-placed) (= b wrongly-placed)))))
(every check1 clues))

(display (filter check (iota 1000)))
(newline)

Re: Parenthesis Pileup (was Re: (Mastermind) puzzle (with 3 digits) -- ...)

<urlg82$3d1ah$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18042&group=comp.lang.lisp#18042

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: Parenthesis Pileup (was Re: (Mastermind) puzzle (with 3 digits)
-- ...)
Date: Tue, 27 Feb 2024 20:21:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <urlg82$3d1ah$2@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87le75emqn.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 27 Feb 2024 20:21:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d339ad4b21c64d41c58c7c072f1b4d54";
logging-data="3573073"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+N17X02JL14FkNmhFxdJT5"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:9T0P09H/qQwwrZeAgGJs8nTcjk8=
 by: Lawrence D'Oliv - Tue, 27 Feb 2024 20:21 UTC

On Tue, 27 Feb 2024 11:22:08 -0800, Paul Rubin wrote:

> Note that the parenthesis style is pretty much universal in Lisp and
> variants.

Sorry, not a fan of “parenthesis pileup” layout.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<20240227124603.164@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18043&group=comp.lang.lisp#18043

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code
Sought
Date: Tue, 27 Feb 2024 20:51:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <20240227124603.164@kylheku.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87le75emqn.fsf@nightsong.com>
Injection-Date: Tue, 27 Feb 2024 20:51:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="923ed161601c41226170687a2c58a566";
logging-data="3585224"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DHmh0xXK5ZjY9llvWaQIabCGD1DsOgPY="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:zXVZSeEY8X4Tn2SSSyjYKG5uNmQ=
 by: Kaz Kylheku - Tue, 27 Feb 2024 20:51 UTC

On 2024-02-27, Paul Rubin <no.email@nospam.invalid> wrote:
> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>> This is my answer after spending this afternoon learning Guile. Much
>> more wordy than the Python version I previously posted. Anybody know
>> how to do it better?
>
> The following works for me as a fairly simple port of the concise Python
> version to Guile.

Based on code formatting alone, I'm declaring yours vastly better.

The problem is actually trivial.

All you have to do is close your parentheses ))) like a sane person, and
the solution will pop out sooner or later.

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

Re: Parenthesis Pileup (was Re: (Mastermind) puzzle (with 3 digits) -- ...)

<20240227125204.655@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18044&group=comp.lang.lisp#18044

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: Parenthesis Pileup (was Re: (Mastermind) puzzle (with 3 digits)
-- ...)
Date: Tue, 27 Feb 2024 20:56:45 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <20240227125204.655@kylheku.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87le75emqn.fsf@nightsong.com> <urlg82$3d1ah$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 27 Feb 2024 20:56:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="923ed161601c41226170687a2c58a566";
logging-data="3585224"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18DDioKvHTaXXhmNkD64Se2SlhsUr4gh6Q="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:FTWwHBh64ifPFqm0essbVpzuE88=
 by: Kaz Kylheku - Tue, 27 Feb 2024 20:56 UTC

On 2024-02-27, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Tue, 27 Feb 2024 11:22:08 -0800, Paul Rubin wrote:
>
>> Note that the parenthesis style is pretty much universal in Lisp and
>> variants.
>
> Sorry, not a fan of “parenthesis pileup” layout.

You've certainly come to the right language family, if you want to
forever hack by yourself, doing things Your Way.

I suspect you're doing your formatting manually, though, which takes
more effort. The parentheses pileup is well supported in editors.

If you don't want collaborators, you can just communicate that
explicitly (e.g. a block comment saying ";; this is my solo work,
patches will be rejected regardless of quality") and not inflict an
unergonomic way of working on yourself.

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

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<87edcxegiu.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18045&group=comp.lang.lisp#18045

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Tue, 27 Feb 2024 13:36:25 -0800
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <87edcxegiu.fsf@nightsong.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="91574d2575cac45da5d1f33a64b22cc2";
logging-data="3606481"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xC/MN97VYHUZF/ugo/xGw"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:HeS223VcWQnNF9fjHVniqwm33QY=
sha1:RU9/MALkGryngpB1xodFSYRCGiM=
 by: Paul Rubin - Tue, 27 Feb 2024 21:36 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> This is my answer after spending this afternoon learning Guile. Much
> more wordy than the Python version I previously posted. Anybody know
> how to do it better?

The "parenthesis pileup" aside, the following things jump out at me:

1) Your "range" function already exists, called "iota" (after the iota
operation in APL).

2) Even if it didn't exist, your recursive definition is messy.
This is more idiomatic:

(define (range n)
(define (go n a)
(if (< n 0)
a
(go (1- n) (cons n a))))
(go n 0))

Note that the accumulation parameter in "go" makes go tail recursive, so
it uses a fixed number of stack cells.

2) Similarly the "score" function looks translated from C to Scheme or
something like that. Generally, the use of set! is a code smell in
Scheme. It's preferable to use recursion and combinators like map and
filter. In Haskell, set! doesn't even exist in any convenient form.

Without destructive updates, you end up using a programming style with a
rather different set of idioms. Scheme was an early enabler of that
style. Lisp predated Scheme and was sort of an intermediate step.
See the SICP book for a deeper intro.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<87a5nleg1a.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18046&group=comp.lang.lisp#18046

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Tue, 27 Feb 2024 13:46:57 -0800
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <87a5nleg1a.fsf@nightsong.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="91574d2575cac45da5d1f33a64b22cc2";
logging-data="3606481"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QKDOu5OwRfbX0bm/hrZdD"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:aNJJGq0o01DUm1V0NK6r7NQkRsY=
sha1:1L20owNDdVP7kNB0h2oUCAT+KCY=
 by: Paul Rubin - Tue, 27 Feb 2024 21:46 UTC

Paul Rubin <no.email@nospam.invalid> writes:
> (define (range n) ...

Oops:

(define (range n)
(define (go n a)
(if (< n 0)
a
(go (1- n) (cons n a))))
(go (1- n) '()))

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<urlonm$3ep9p$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18047&group=comp.lang.lisp#18047

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code
Sought
Date: Tue, 27 Feb 2024 22:46:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <urlonm$3ep9p$2@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 27 Feb 2024 22:46:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d339ad4b21c64d41c58c7c072f1b4d54";
logging-data="3630393"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yB8dLFEBO3JOdcmmhR4RZ"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:6nPAAtbTWnfakNxl2YrUquCliSw=
 by: Lawrence D'Oliv - Tue, 27 Feb 2024 22:46 UTC

On Tue, 27 Feb 2024 13:36:25 -0800, Paul Rubin wrote:

> 1) Your "range" function already exists, called "iota" (after the iota
> operation in APL).

Just checked, and I don’t even need to import anything to use it. Thanks.

> 2) Similarly the "score" function looks translated from C to Scheme or
> something like that.

It was my attempt to translate this Python code:

def score(candidate, answer) :
return \
(
sum(a == b for a, b in zip(candidate, answer)),
sum
(
i != j and a == b
for i, a in enumerate(candidate)
for j, b in enumerate(answer)
)
)
#end score

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<871q8xe4xj.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18053&group=comp.lang.lisp#18053

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Tue, 27 Feb 2024 17:46:48 -0800
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <871q8xe4xj.fsf@nightsong.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b11dea1ec4537807cb9ed89e3ac624c7";
logging-data="3696691"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1++cmL+wmANrLM7xu72naqF"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:HCiKRhuzgwRcoxNmwhnX7imLLXY=
sha1:bg1VeQbSptq8ikMPwU8B7AzRw9M=
 by: Paul Rubin - Wed, 28 Feb 2024 01:46 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> sum(a == b for a, b in zip(candidate, answer))

zip is in srfi-1 but I would write this as

(length (filter identity (map = candidate answer)))

> sum
> (
> i != j and a == b
> for i, a in enumerate(candidate)
> for j, b in enumerate(answer)
> )
> )

In Python you might avoid the nested loops by writing that in terms of
set or multiset (collections.Counter) intersections. In Scheme, maybe
this:

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

lset-intersection is also in srfi-1. Here, candidate and answer are
both lists of digits. I don't know the running time (complexity) of
lset-intersection. In Python, sets are represented with hashes so the
equivalent operation should take linear time. Scheme might uses hashes
(linear time), sorted lists (n log n time), or quadratic time.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<uroa8p$3lu2$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18059&group=comp.lang.lisp#18059

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code
Sought
Date: Wed, 28 Feb 2024 21:57:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uroa8p$3lu2$2@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 28 Feb 2024 21:57:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2b5f550de027bed53e7de3d0720ccb3e";
logging-data="120770"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XxfawjPC4WfdqVX9tJ53T"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:ZjNm2IwqiAT5x7fvSPSDnaxQ3SE=
 by: Lawrence D'Oliv - Wed, 28 Feb 2024 21:57 UTC

On Tue, 27 Feb 2024 17:46:48 -0800, Paul Rubin wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> sum
>> (
>> i != j and a == b for i, a in enumerate(candidate)
>> for j, b in enumerate(answer)
>> )
>
> In Python you might avoid the nested loops by writing that in terms of
> set or multiset (collections.Counter) intersections.

Why would that be better?

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<49gvtitvd567m3u58j5qubarrh7qvdilml@4ax.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18060&group=comp.lang.lisp#18060

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!.POSTED!not-for-mail
From: gneuner2@comcast.net (George Neuner)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Wed, 28 Feb 2024 18:29:50 -0500
Organization: i2pn2 (i2pn.org)
Message-ID: <49gvtitvd567m3u58j5qubarrh7qvdilml@4ax.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me> <87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me> <871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: i2pn2.org;
logging-data="282721"; mail-complaints-to="usenet@i2pn2.org";
posting-account="h5eMH71iFfocGZucc+SnA0y5I+72/ecoTCcIjMd3Uww";
User-Agent: ForteAgent/8.00.32.1272
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: George Neuner - Wed, 28 Feb 2024 23:29 UTC

On Wed, 28 Feb 2024 21:57:46 -0000 (UTC), Lawrence D'Oliveiro
<ldo@nz.invalid> wrote:

>On Tue, 27 Feb 2024 17:46:48 -0800, Paul Rubin wrote:
>
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>
>>> sum
>>> (
>>> i != j and a == b for i, a in enumerate(candidate)
>>> for j, b in enumerate(answer)
>>> )
>>
>> In Python you might avoid the nested loops by writing that in terms of
>> set or multiset (collections.Counter) intersections.
>
>Why would that be better?

Because almost all of Python's standard libraries are written in C.
Most versions of Python are just too slow to use for anything but toy
programs.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<8734tcta9j.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18061&group=comp.lang.lisp#18061

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Wed, 28 Feb 2024 15:54:48 -0800
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <8734tcta9j.fsf@nightsong.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b872400a71d39c8346220974146acd12";
logging-data="167539"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vkhu4coyWel3xoGBX99I6"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:vy3AkEqccuYcC06tSMp0/15MN0w=
sha1:J6Oio5+v5kNpJdT7rK80bk1A2pc=
 by: Paul Rubin - Wed, 28 Feb 2024 23:54 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>> In Python you might avoid the nested loops by writing that in terms of
>> set or multiset (collections.Counter) intersections.
> Why would that be better?

You are trying to handle N digits and your algorithm does O(N**2)
comparisons. Ok, I guess the whole search strategy is impractical if N
is larger than just a few, and in traditional Mastermind N=4, so maybe
that isn't an issue. But the idea is that sets in Python are
implemented with hashing, so finding a set intersection is takes O(N).

A purely functional approach (idk how lset in Guile works) might use
sorted lists for O(N log N) complexity, but either beats O(N**2).

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<urqs1c$q9h9$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18062&group=comp.lang.lisp#18062

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code
Sought
Date: Thu, 29 Feb 2024 21:13:17 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <urqs1c$q9h9$2@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
<8734tcta9j.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 29 Feb 2024 21:13:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="daeb6559b2144face1d3464670b018f1";
logging-data="861737"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195QYxKf2xtFt8QewWSqxAP"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:bDwsfNvm+ds9Z/bsyHRiVIN27C4=
 by: Lawrence D'Oliv - Thu, 29 Feb 2024 21:13 UTC

On Wed, 28 Feb 2024 15:54:48 -0800, Paul Rubin wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>
>> Why would that be better?
>
> You are trying to handle N digits and your algorithm does O(N**2)
> comparisons. Ok, I guess the whole search strategy is impractical if N
> is larger than just a few, and in traditional Mastermind N=4, so maybe
> that isn't an issue.

“Premature optimization is the root of all evil.”
-- variously attributed to Tony Hoare or Donald Knuth

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<871q8ugbdz.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18063&group=comp.lang.lisp#18063

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Thu, 29 Feb 2024 14:21:12 -0800
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <871q8ugbdz.fsf@nightsong.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
<8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="b872400a71d39c8346220974146acd12";
logging-data="887701"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XgaYyA54H7JSo3vsBmHKt"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:/YtCNiw+AY5xQX6yyOenNC49fOU=
sha1:NuIsfLNj3qhn2SY762voUL4ax6I=
 by: Paul Rubin - Thu, 29 Feb 2024 22:21 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> “Premature optimization is the root of all evil.”

I would say using set intersections is clearer and more concise than
that code with loop indices too. It is what you were trying to compute
in the first place. Same idea as writing a matrix product as A*B
instead of as some messy thing with subscripts.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<urr5ka$rvtd$7@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18064&group=comp.lang.lisp#18064

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code
Sought
Date: Thu, 29 Feb 2024 23:56:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <urr5ka$rvtd$7@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
<8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me>
<871q8ugbdz.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 29 Feb 2024 23:56:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="08fcff3ec016520633046216dcf0e434";
logging-data="917421"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hxGQ0/ANNIYNtvrLwkmUf"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:5smpgoFbtU3Hullo+hILEbPqZ3I=
 by: Lawrence D'Oliv - Thu, 29 Feb 2024 23:56 UTC

On Thu, 29 Feb 2024 14:21:12 -0800, Paul Rubin wrote:

> Same idea as writing a matrix product as A*B instead of as some messy
> thing with subscripts.

Somebody still has to write the underlying code with the subscripts.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<20240229162403.123@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18065&group=comp.lang.lisp#18065

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code
Sought
Date: Fri, 1 Mar 2024 00:24:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <20240229162403.123@kylheku.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
<8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 1 Mar 2024 00:24:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="24c55e5273c316a14a1eea66477d3f37";
logging-data="934164"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RD+wh5wExHpWqbhp9zGiVm5Azkj8HsO0="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:IgM1OZ11AAVbPuaym7h0RUY9bkg=
 by: Kaz Kylheku - Fri, 1 Mar 2024 00:24 UTC

On 2024-02-29, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Wed, 28 Feb 2024 15:54:48 -0800, Paul Rubin wrote:
>
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>>
>>> Why would that be better?
>>
>> You are trying to handle N digits and your algorithm does O(N**2)
>> comparisons. Ok, I guess the whole search strategy is impractical if N
>> is larger than just a few, and in traditional Mastermind N=4, so maybe
>> that isn't an issue.
>
> “Premature optimization is the root of all evil.”
> -- variously attributed to Tony Hoare or Donald Knuth

Pinning it down more precisely at this stage would be premature
attribution.

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

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<87wmqmelu0.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18067&group=comp.lang.lisp#18067

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Thu, 29 Feb 2024 18:18:31 -0800
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <87wmqmelu0.fsf@nightsong.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
<8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me>
<871q8ugbdz.fsf@nightsong.com> <urr5ka$rvtd$7@dont-email.me>
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/udWWzEWdSRxA1jHMzlcWc"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:w17yQ2dcQaMgvvlGGm/4YDSplN8=
sha1:bLUKfYH/Klo6T+cW0BJwBQjD1kE=
 by: Paul Rubin - Fri, 1 Mar 2024 02:18 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> Somebody still has to write the underlying code with the subscripts.

Sure, that's pushed down into a library or helper function though.
Doing it at the higher level is related to the "primitive obsession"
antipattern. It's normal to bang out code like that when you're trying
to keep moving, but refactoring afterwards generally helps. Here's a
refactored Python version of the score function I posted earlier:

def score(answer: int, candidate: int) -> Tuple[int,int]:
a = digits(answer)
b = digits(candidate)
well_placed = sum(x==y for x,y in zip(a,b))
wrongly_placed = len(set(a) & set(b)) - well_placed
return well_placed, wrongly_placed

Maybe it's more correct to use multisets (collections.Counter) instead
of sets, depending on how the problem is specified.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<urrhat$11rgn$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18070&group=comp.lang.lisp#18070

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code
Sought
Date: Fri, 1 Mar 2024 03:16:45 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <urrhat$11rgn$3@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
<8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me>
<871q8ugbdz.fsf@nightsong.com> <urr5ka$rvtd$7@dont-email.me>
<87wmqmelu0.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 1 Mar 2024 03:16:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="08fcff3ec016520633046216dcf0e434";
logging-data="1109527"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/g/cEW+v2FJ5XyRTvFV/IB"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:jlcOgHKcl7yTpVEA9PlgHRED7S4=
 by: Lawrence D'Oliv - Fri, 1 Mar 2024 03:16 UTC

On Thu, 29 Feb 2024 18:18:31 -0800, Paul Rubin wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> Somebody still has to write the underlying code with the subscripts.
>
> Sure, that's pushed down into a library or helper function though. Doing
> it at the higher level is related to the "primitive obsession"
> antipattern.

I only push things into separate/library functions if I’m going to reuse
them. Splitting things off just for the sake of doing so is what we could
call a “fragmentation smell” or a “gratuitous hierarchy antipattern”.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<87le72ei9p.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18071&group=comp.lang.lisp#18071

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Thu, 29 Feb 2024 19:35:30 -0800
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <87le72ei9p.fsf@nightsong.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
<8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me>
<871q8ugbdz.fsf@nightsong.com> <urr5ka$rvtd$7@dont-email.me>
<87wmqmelu0.fsf@nightsong.com> <urrhat$11rgn$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="943bcaa197a75ee88da3147cd0703006";
logging-data="1116582"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX190nkHXPWmG76YJerLd2xjt"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:xjJXbawuwjGAMnGostvz5ni/8f4=
sha1:fp3QK2dGIxDIOuGzSUNYM1J3P5g=
 by: Paul Rubin - Fri, 1 Mar 2024 03:35 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> I only push things into separate/library functions if I’m going to reuse
> them. Splitting things off just for the sake of doing so is what we could
> call a “fragmentation smell” or a “gratuitous hierarchy antipattern”.

In the case of matrix multiplication, the code is already in a linear
algebra library. In the case of set intersection, it is built into
Python's set type.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<87zfvi5ipv.fsf@eder.anydns.info>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18073&group=comp.lang.lisp#18073

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Followup: comp.lang.scheme
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: a_eder_muc@web.de (Andreas Eder)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Followup-To: comp.lang.scheme
Date: Fri, 01 Mar 2024 11:50:36 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <87zfvi5ipv.fsf@eder.anydns.info>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="f98840aacfbedad24b3dd4823636d70d";
logging-data="1270418"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197RPA+B8AOseVpCaoCvgb1"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:4lSoPR+gRsaJKrlt0iGY2Gu03aI=
sha1:/fz9ypnxdENwEduu79CkBRxjkec=
 by: Andreas Eder - Fri, 1 Mar 2024 10:50 UTC

On Di 27 Feb 2024 at 13:36, Paul Rubin <no.email@nospam.invalid> wrote:

> The "parenthesis pileup" aside, the following things jump out at me:
>
> 1) Your "range" function already exists, called "iota" (after the iota
> operation in APL).
>
> 2) Even if it didn't exist, your recursive definition is messy.
> This is more idiomatic:
>
> (define (range n)
> (define (go n a)
> (if (< n 0)
> a
> (go (1- n) (cons n a))))
> (go n 0))
>
I would write it without the second define using a named let:

(define (range n)
(let go ((n n) (a '()))
(if (< n 0)
a
(go (1- n) (cons n a)))))

'Andreas

--
ceterum censeo redmondinem esse delendam

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<us1faq$2dsg1$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18076&group=comp.lang.lisp#18076

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED.2001:818:dc66:5e00:202:44ff:fe9c:2638!not-for-mail
From: nunojsilva@invalid.invalid (Nuno Silva)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Sun, 03 Mar 2024 09:23:02 +0000
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <us1faq$2dsg1$1@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
<8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me>
<20240229162403.123@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="2001:818:dc66:5e00:202:44ff:fe9c:2638";
logging-data="2552321"; mail-complaints-to="abuse@eternal-september.org"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Nuno Silva - Sun, 3 Mar 2024 09:23 UTC

On 2024-03-01, Kaz Kylheku wrote:

> On 2024-02-29, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
>> On Wed, 28 Feb 2024 15:54:48 -0800, Paul Rubin wrote:
>>
>>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>>>
>>>> Why would that be better?
>>>
>>> You are trying to handle N digits and your algorithm does O(N**2)
>>> comparisons. Ok, I guess the whole search strategy is impractical if N
>>> is larger than just a few, and in traditional Mastermind N=4, so maybe
>>> that isn't an issue.
>>
>> “Premature optimization is the root of all evil.”
>> -- variously attributed to Tony Hoare or Donald Knuth
>
> Pinning it down more precisely at this stage would be premature
> attribution.

I sometimes feel that this specific sentence from Knuth's quote might be
being used as a way to discourage even thinking about optimization, when
the intent of the whole quote might be actually the opposite: yes, there
are places where it doesn't bring much benefit to optimize, but there
are also the parts where it *does*.

"We should forget about small efficiencies, say about 97% of the
time: premature optimization is the root of all evil. Yet we should
not pass up our opportunities in that critical 3%."

But I'll read the whole thing when I can, at this point I'm not even
sure I've read this before or not...

https://dl.acm.org/doi/10.1145/356635.356640

--
Nuno Silva
(not reading comp.lang.scheme, just comp.lang.lisp)

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<us2l76$2ltj3$4@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18077&group=comp.lang.lisp#18077

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code
Sought
Date: Sun, 3 Mar 2024 20:05:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <us2l76$2ltj3$4@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
<8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me>
<20240229162403.123@kylheku.com> <us1faq$2dsg1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 3 Mar 2024 20:05:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1df16df39307445c7cddc792d9e0afb1";
logging-data="2815587"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183ARnaIIiyRwj5AkO0FUAl"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:uDvAwOENr4mgwyaspC4GT3/2ZwE=
 by: Lawrence D'Oliv - Sun, 3 Mar 2024 20:05 UTC

On Sun, 03 Mar 2024 09:23:02 +0000, Nuno Silva wrote:

> yes, there are places where it doesn't bring much benefit to optimize,
> but there are also the parts where it *does*.

The point being, you determine those by actually running benchmarks on
your code. Programmers who assume they know which parts need speeding up a
priori are often surprised to discover they’re wrong.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<31ee5ecaf0edef2a085326ac998363d8@www.novabbs.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18078&group=comp.lang.lisp#18078

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!.POSTED!not-for-mail
From: HenHanna@dev.null (HenHanna)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Sun, 3 Mar 2024 22:56:25 +0000
Organization: novaBBS
Message-ID: <31ee5ecaf0edef2a085326ac998363d8@www.novabbs.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me> <87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me> <871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me> <8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me> <20240229162403.123@kylheku.com> <us1faq$2dsg1$1@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="731526"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$EoNSD32wmpLlsolVqUGqmOLiBYH/kkG0iKfceh3YZhLqxzV./wX.i
X-Rslight-Posting-User: 5a1f1f09909a70d7ae18ae9af00e018f83ece577
X-Spam-Checker-Version: SpamAssassin 4.0.0
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
 by: HenHanna - Sun, 3 Mar 2024 22:56 UTC

sum ( i != j and a == b for i, a in enumerate(candidate)
for j, b in enumerate(answer) )

--------- i certainly enjoyed seeing this code. Thanks for sharing it!

it's written in a [functional] or [mathematical] or "comprehensive" style.

Nuno Silva wrote:

> On 2024-03-01, Kaz Kylheku wrote:

>> On 2024-02-29, Lawrence D'Oliveiro <ldo@nz.invalid> wrote: .....

>>>
>>> “Premature optimization is the root of all evil.”
>>> ----- variously attributed to Tony Hoare or Donald Knuth

and not Perlis?

>> Pinning it down more precisely at this stage would be premature attribution.

> I sometimes feel that this specific sentence from Knuth's quote might be
> being used as a way to discourage even thinking about optimization, when
> the intent of the whole quote might be actually the opposite: yes, there
> are places where it doesn't bring much benefit to optimize, but there
> are also the parts where it *does*.

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<us3103$2of1i$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18079&group=comp.lang.lisp#18079

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code
Sought
Date: Sun, 3 Mar 2024 23:27:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <us3103$2of1i$1@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me>
<87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me>
<871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me>
<8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me>
<20240229162403.123@kylheku.com> <us1faq$2dsg1$1@dont-email.me>
<31ee5ecaf0edef2a085326ac998363d8@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 3 Mar 2024 23:27:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ebd4c9541601cb1e1312dcde6a0cb96a";
logging-data="2898994"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+DqYZMQ7V2om0mu7iohwg1"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:KP0iEhIayUdkZQbr73LAfZCJspM=
 by: Lawrence D'Oliv - Sun, 3 Mar 2024 23:27 UTC

On Sun, 3 Mar 2024 22:56:25 +0000, HenHanna wrote:

> it's written in a [functional] or [mathematical] or
> "comprehensive" style.

Yup, I like writing functional constructs in primarily-procedural
languages. It’s better than trying to work in supposedly pure-functional
languages.

Python also uses the term “comprehension” for certain uses of that kind of
construct.

> and not Perlis?

I like another quote of his: “There are two ways to write error-free
programs; only the third one works.”

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought

<ec96ca8d22ac4bbba9baf649a89c97a1@www.novabbs.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18080&group=comp.lang.lisp#18080

  copy link   Newsgroups: comp.lang.scheme comp.lang.lisp
Path: i2pn2.org!.POSTED!not-for-mail
From: HenHanna@dev.null (HenHanna)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Mon, 4 Mar 2024 10:30:26 +0000
Organization: novaBBS
Message-ID: <ec96ca8d22ac4bbba9baf649a89c97a1@www.novabbs.com>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me> <87edcxegiu.fsf@nightsong.com> <urlonm$3ep9p$2@dont-email.me> <871q8xe4xj.fsf@nightsong.com> <uroa8p$3lu2$2@dont-email.me> <8734tcta9j.fsf@nightsong.com> <urqs1c$q9h9$2@dont-email.me> <20240229162403.123@kylheku.com> <us1faq$2dsg1$1@dont-email.me> <31ee5ecaf0edef2a085326ac998363d8@www.novabbs.com> <us3103$2of1i$1@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="781049"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
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-Rslight-Site: $2y$10$kyrH5g3Hpc0pcENAaZmIzeltYkt2efYrwOtEHWJXEqFJLtQv7nOkm
X-Rslight-Posting-User: 5a1f1f09909a70d7ae18ae9af00e018f83ece577
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: HenHanna - Mon, 4 Mar 2024 10:30 UTC

Lawrence D'Oliveiro wrote:

> On Sun, 3 Mar 2024 22:56:25 +0000, HenHanna wrote:

>> it's written in a [functional] or [mathematical] or "comprehensive" style.

> Yup, I like writing functional constructs in primarily-procedural
> languages. It’s better than trying to work in supposedly pure-functional
> languages.

> Python also uses the term “comprehension” for certain uses of that kind of construct.

>> and not Perlis?

> I like another quote of his: “There are two ways to write error-free
> programs; only the third one works.”

i love it.... i thought it must be THE most enigmatic of his quotes, but...

https://www.cs.yale.edu/homes/perlis-alan/quotes.html

38. Structured Programming supports the law of the excluded middle. --------- ??????????

39. Re graphics: A picture is worth 10K words - but only those to describe the picture. Hardly any sets of 10K words can be adequately described with pictures.

40. There are two ways to write error-free programs; only the third one works.

41. Some programming languages manage to absorb change, but withstand progress. -------- For example?????

42. You can measure a programmer's perspective by noting his attitude on the continuing vitality of FORTRAN.

43. In software systems, it is often the early bird that makes the worm. ---------- meaning, ...that introduces the BUG ?

44.Sometimes I think the only universal in the computing field is the fetch-execute cycle.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor