Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #205: Quantum dynamics are affecting the transistors


comp / comp.lang.lisp / Re: How do i get multiple Min() values?

SubjectAuthor
* How do i get multiple Min() values?HenHanna
+* Re: How do i get multiple Min() values?HenHanna
|`* Re: How do i get multiple Min() values?Kaz Kylheku
| `* Re: How do i get multiple Min() values?Madhu
|  +- Re: How do i get multiple Min() values?Madhu
|  `- Re: How do i get multiple Min() values?Nuno Silva
`* Re: How do i get multiple Min() values?B. Pym
 +- Re: How do i get multiple Min() values?HenHanna
 +- Re: How do i get multiple Min() values?B. Pym
 `- Re: How do i get multiple Min() values?B. Pym

1
Subject: How do i get multiple Min() values?
From: HenHanna
Newsgroups: comp.lang.python, comp.lang.lisp
Organization: A noiseless patient Spider
Date: Fri, 12 Jul 2024 09:49 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.python,comp.lang.lisp
Subject: How do i get multiple Min() values?
Date: Fri, 12 Jul 2024 02:49:41 -0700
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <v6qu7m$2vg8q$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 12 Jul 2024 11:49:43 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b06fdc280b8cb7a95d947834e5bad7df";
logging-data="3129626"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rKpXB7H9s1xJaIHCJzfJJKdc+c5exX0o="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:plRA8pszGCT8/J+MaXGyK/1GJeA=
Content-Language: en-US
View all headers

How do i get multiple Min() values?

e.g. for Y = (x-2)*(x-3) for x in range(-10,10)
the min Y is hit twice

print( min( ((x-2)*(x-3), (x, (x-2, x-3)))
for x in range(-10,10) ) )

is this easy in Scheme(Gauche) ?

Subject: Re: How do i get multiple Min() values?
From: HenHanna
Newsgroups: comp.lang.python, comp.lang.lisp, sci.lang
Organization: A noiseless patient Spider
Date: Fri, 12 Jul 2024 19:00 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.python,comp.lang.lisp,sci.lang
Subject: Re: How do i get multiple Min() values?
Date: Fri, 12 Jul 2024 12:00:22 -0700
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <v6rug7$35c6s$2@dont-email.me>
References: <v6qu7m$2vg8q$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 12 Jul 2024 21:00:24 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="13ab68f9fb6c4be36bb820e4a5191e48";
logging-data="3322076"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199/BWlMyufpfhwumHRVOLDNF0YYcd6l54="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1://H6UF1oRpERuBOKx5Itcx6QfOo=
Content-Language: en-US
In-Reply-To: <v6qu7m$2vg8q$1@dont-email.me>
View all headers

>
> How do i get multiple Min() values?
>
>           e.g.      for   Y = (x-2)*(x-3)   for x in range(-10,10)
>                                    the min Y is hit twice
>
>
> print(  min( ((x-2)*(x-3),  (x, (x-2, x-3)))
>                                            for x in range(-10,10) ) )
>
>
>
> is this easy in Scheme(Gauche) ?

if the Min() is going to check all of the Candidate values,
it could (at least) tell us how many times the Min value was seen!

Subject: Re: How do i get multiple Min() values?
From: B. Pym
Newsgroups: comp.lang.python, comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 13 Jul 2024 12:56 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.python,comp.lang.lisp
Subject: Re: How do i get multiple Min() values?
Date: Sat, 13 Jul 2024 12:56:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <v6tthj$3jj0a$1@dont-email.me>
References: <v6qu7m$2vg8q$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Date: Sat, 13 Jul 2024 14:56:23 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d09d726af6555b9317b37815791b403a";
logging-data="3787786"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+S6WACAaZXZN6zOuuKB5LC"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:UbljrtXzvaGs3ba2b/qe394DrXQ=
View all headers

HenHanna wrote:

>
> How do i get multiple Min() values?
>
> e.g. for Y = (x-2)*(x-3) for x in range(-10,10)
> the min Y is hit twice
>
>
> print( min( ((x-2)*(x-3), (x, (x-2, x-3)))
> for x in range(-10,10) ) )
>
>
>
> is this easy in Scheme(Gauche) ?

Gauche Scheme

(use gauche.collection) ;; fold2

(define (min-by fn lst)
(if (null? lst)
(values '() #f)
(fold2
(lambda (x best worth)
(let ((score (fn x)))
(cond ((< score worth) (values (list x) score))
((= score worth) (values (cons x best) worth))
(#t (values best worth)))))
(take lst 1) (fn (car lst))
(cdr lst))))

(min-by (lambda(x) (* (- x 2) (- x 3))) (lrange -10 11))

===>
(3 2)
0

Subject: Re: How do i get multiple Min() values?
From: HenHanna
Newsgroups: comp.lang.python, comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 13 Jul 2024 18:06 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.python,comp.lang.lisp
Subject: Re: How do i get multiple Min() values?
Date: Sat, 13 Jul 2024 11:06:04 -0700
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <v6ufmc$3mo35$1@dont-email.me>
References: <v6qu7m$2vg8q$1@dont-email.me> <v6tthj$3jj0a$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 13 Jul 2024 20:06:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0b2917fef9857da2f467d2527da3b2d2";
logging-data="3891301"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gCcpvIBVIzd+1phClfVop2WhRqwxX2mg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:isFCfBGRcH8wIZ7CAwG/7uYH7NU=
In-Reply-To: <v6tthj$3jj0a$1@dont-email.me>
Content-Language: en-US
View all headers

On 7/13/2024 5:56 AM, B. Pym wrote:
> HenHanna wrote:
>
>>
>> How do i get multiple Min() values?
>>
>> e.g. for Y = (x-2)*(x-3) for x in range(-10,10)
>> the min Y is hit twice
>>
>>
>> print( min( ((x-2)*(x-3), (x, (x-2, x-3)))
>> for x in range(-10,10) ) )
>>
>>
>>
>> is this easy in Scheme(Gauche) ?
>
> Gauche Scheme
>
> (use gauche.collection) ;; fold2
>
> (define (min-by fn lst)
> (if (null? lst)
> (values '() #f)
> (fold2
> (lambda (x best worth)
> (let ((score (fn x)))
> (cond ((< score worth) (values (list x) score))
> ((= score worth) (values (cons x best) worth))
> (#t (values best worth)))))
> (take lst 1) (fn (car lst))
> (cdr lst))))
>
> (min-by (lambda(x) (* (- x 2) (- x 3))) (lrange -10 11))
>
> ===>
> (3 2)
> 0
>

Thank you... i think Python and Scheme(Gauche) should give
me this by default:

a list(collection) of all the
( key1 "data1" ... etc )
( key2 "data2" ... etc ) ...

for which the Min key value was seen.

Subject: Re: How do i get multiple Min() values?
From: B. Pym
Newsgroups: comp.lang.python, comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 13 Jul 2024 19:11 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.python,comp.lang.lisp
Subject: Re: How do i get multiple Min() values?
Date: Sat, 13 Jul 2024 19:11:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <v6ujg9$3nd4k$1@dont-email.me>
References: <v6qu7m$2vg8q$1@dont-email.me> <v6tthj$3jj0a$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Date: Sat, 13 Jul 2024 21:11:07 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="bb9db39bc7686b389eb5c60179405e43";
logging-data="3912852"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FLSb+EvF0oD+IbwinEijB"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:5uXb9pigYNHeAVbw0w3VLteWLDM=
View all headers

B. Pym wrote:

> HenHanna wrote:
>
> >
> > How do i get multiple Min() values?
> >
> > e.g. for Y = (x-2)*(x-3) for x in range(-10,10)
> > the min Y is hit twice
> >
> >
> > print( min( ((x-2)*(x-3), (x, (x-2, x-3)))
> > for x in range(-10,10) ) )
> >
> >
> >
> > is this easy in Scheme(Gauche) ?
>
> Gauche Scheme
>
> (use gauche.collection) ;; fold2
>
> (define (min-by fn lst)
> (if (null? lst)
> (values '() #f)
> (fold2
> (lambda (x best worth)
> (let ((score (fn x)))
> (cond ((< score worth) (values (list x) score))
> ((= score worth) (values (cons x best) worth))
> (#t (values best worth)))))
> (take lst 1) (fn (car lst))
> (cdr lst))))
>
> (min-by (lambda(x) (* (- x 2) (- x 3))) (lrange -10 11))
>
> ===>
> (3 2)
> 0
>

(use gauche.collection) ;; fold2

(define (min-max-by fn lst)
(define (use compare x score best worth)
(cond ((compare score worth) (list (list x) score))
((= score worth) (list (cons x best) worth))
(#t (list best worth))))
(if (null? lst)
(values (list '() #f) (list '() #f))
(let ((initial (list (take lst 1) (fn (car lst)))))
(fold2
(lambda (x mini maxi)
(let ((score (fn x)))
(values
(apply use < x score mini)
(apply use > x score maxi))))
initial initial
(cdr lst)))))

(min-max-by (lambda(x) (* (- x 2) (- x 3))) (lrange -10 11))

===>
((3 2) 0)
((-10) 156)

Subject: Re: How do i get multiple Min() values?
From: Kaz Kylheku
Newsgroups: comp.lang.python, comp.lang.lisp, sci.lang
Organization: A noiseless patient Spider
Date: Mon, 15 Jul 2024 12:27 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.python,comp.lang.lisp,sci.lang
Subject: Re: How do i get multiple Min() values?
Date: Mon, 15 Jul 2024 12:27:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <20240715051340.619@kylheku.com>
References: <v6qu7m$2vg8q$1@dont-email.me> <v6rug7$35c6s$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 15 Jul 2024 14:27:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cf4046d13f74d7012fcb7650b259afb8";
logging-data="737865"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pDm54YbA3+gzl45I4HHf7Cd9F/Qm+QBM="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:RCBbPJryMnZbd2mM1bA4X+Aqz1M=
View all headers

On 2024-07-12, HenHanna <HenHanna@devnull.tb> wrote:
>>
>> How do i get multiple Min() values?
>>
>>           e.g.      for   Y = (x-2)*(x-3)   for x in range(-10,10)
>>                                    the min Y is hit twice
>>
>>
>> print(  min( ((x-2)*(x-3),  (x, (x-2, x-3)))
>>                                            for x in range(-10,10) ) )
>>
>>
>>
>> is this easy in Scheme(Gauche) ?
>
>
> if the Min() is going to check all of the Candidate values,
> it could (at least) tell us how many times the Min value was seen!

I decided to add something like this to TXR Lisp.

It will appear in 296.

This is the TXR Lisp interactive listener of TXR 295.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
When transferring between containers, do not siphon TXR by mouth.
1> (find-mins -10..11 : [callf * pppred ppred])
(2 3)
2> (find-mins (vec-seq -10..11) : [callf * pppred ppred])
#(2 3)
3> (find-mins "abracadabra")
"aaaaa"
4> (find-maxes "abracacabra")
"rr"

I works with any less-like function, assuming equality
when it’s neither true that x is less than y, nor that
y is less than x.
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Subject: Re: How do i get multiple Min() values?
From: Madhu
Newsgroups: comp.lang.lisp
Organization: Motzarella
Date: Tue, 16 Jul 2024 15:45 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: How do i get multiple Min() values?
Date: Tue, 16 Jul 2024 21:15:55 +0530
Organization: Motzarella
Lines: 60
Message-ID: <m3a5ih1gss.fsf@leonis4.robolove.meer.net>
References: <v6qu7m$2vg8q$1@dont-email.me> <v6rug7$35c6s$2@dont-email.me>
<20240715051340.619@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 16 Jul 2024 17:45:43 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="603ad98f9877f7a58ead02fbcf0c5817";
logging-data="1406628"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xfRWN2HBYo0U//SpWuH5no2cqqGzc4pA="
Cancel-Lock: sha1:qCLPCsAeO4Ol95MYhNVGBFq05TY=
sha1:VGM5YM8Gy1HZq6N5iDWUOr5jQNU=
View all headers

* Kaz Kylheku <20240715051340.619@kylheku.com> :
Wrote on Mon, 15 Jul 2024 12:27:58 -0000 (UTC):

> On 2024-07-12, HenHanna <HenHanna@devnull.tb> wrote:
>>>
>>> How do i get multiple Min() values?

You just need the count of the min value. you don't really need
"multiple min() values". right?

>>> e.g. for Y = (x-2)*(x-3) for x in range(-10,10)
>>> the min Y is hit twice
>>>
>>> print( min( ((x-2)*(x-3), (x, (x-2, x-3)))
>>> for x in range(-10,10) ) )
>>>
>>> is this easy in Scheme(Gauche) ?

>> if the Min() is going to check all of the Candidate values,
>> it could (at least) tell us how many times the Min value was seen!
>
> I decided to add something like this to TXR Lisp.
>
> It will appear in 296.
>
> This is the TXR Lisp interactive listener of TXR 295.
> Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
> When transferring between containers, do not siphon TXR by mouth.
> 1> (find-mins -10..11 : [callf * pppred ppred])
> (2 3)
> 2> (find-mins (vec-seq -10..11) : [callf * pppred ppred])
> #(2 3)
> 3> (find-mins "abracadabra")
> "aaaaa"
> 4> (find-maxes "abracacabra")
> "rr"
>
> I works with any less-like function, assuming equality
> when it's neither true that x is less than y, nor that
> y is less than x.

Ugh. One would think it is be trivial in CL to track the min-count as a
wrapper around (reduce #'min list)

but the REDUCE spec makes it hairy to get edge cases right (where the
input is an empty list or singleton list).

(defun hen-min (list &aux (min-count 1))
"LIST is a list of numbers. Return the MIN of the list. Second
return value is the count of the MIN in the given LIST"
(values (reduce (lambda (&optional a b)
(when a
(prog1 (min a b)
(cond ((< b a) (setq min-count 1))
((= b a) (incf min-count))))))
list)
(if (endp list) 0 min-count)))

It still reads nicer without any [???]

Subject: Re: How do i get multiple Min() values?
From: Madhu
Newsgroups: comp.lang.lisp
Organization: Motzarella
Date: Tue, 16 Jul 2024 16:43 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: How do i get multiple Min() values?
Date: Tue, 16 Jul 2024 22:13:46 +0530
Organization: Motzarella
Lines: 101
Message-ID: <m31q3t1e4d.fsf@leonis4.robolove.meer.net>
References: <v6qu7m$2vg8q$1@dont-email.me> <v6rug7$35c6s$2@dont-email.me>
<20240715051340.619@kylheku.com>
<m3a5ih1gss.fsf@leonis4.robolove.meer.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 16 Jul 2024 18:43:34 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c3eb4ac05ac99cb517b2891f78ffe1a0";
logging-data="1426025"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tdnhitD9OayfkEcSTF7lQ4v8y1FOtYSg="
Cancel-Lock: sha1:k6yEEClzuiCn3AJEM/XtP2nEGEE=
sha1:RvHWXb3fNh3D9GeXYEChjjiWlvE=
View all headers

* Madhu <m3a5ih1gss.fsf@leonis4.robolove.meer.net> :
Wrote on Tue, 16 Jul 2024 21:15:55 +0530:
> * Kaz Kylheku <20240715051340.619@kylheku.com> :
> Wrote on Mon, 15 Jul 2024 12:27:58 -0000 (UTC):
>
>> On 2024-07-12, HenHanna <HenHanna@devnull.tb> wrote:
>>>>
>>>> How do i get multiple Min() values?
>
> You just need the count of the min value. you don't really need
> "multiple min() values". right?
>
>>>> e.g. for Y = (x-2)*(x-3) for x in range(-10,10)
>>>> the min Y is hit twice
>>>>
>>>> print( min( ((x-2)*(x-3), (x, (x-2, x-3)))
>>>> for x in range(-10,10) ) )
>>>>
>>>> is this easy in Scheme(Gauche) ?
>
>>> if the Min() is going to check all of the Candidate values,
>>> it could (at least) tell us how many times the Min value was seen!
>>
>> I decided to add something like this to TXR Lisp.
>>
>> It will appear in 296.
>>
>> This is the TXR Lisp interactive listener of TXR 295.
>> Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
>> When transferring between containers, do not siphon TXR by mouth.
>> 1> (find-mins -10..11 : [callf * pppred ppred])
>> (2 3)
>> 2> (find-mins (vec-seq -10..11) : [callf * pppred ppred])
>> #(2 3)
>> 3> (find-mins "abracadabra")
>> "aaaaa"
>> 4> (find-maxes "abracacabra")
>> "rr"
>>
>> I works with any less-like function, assuming equality
>> when it's neither true that x is less than y, nor that
>> y is less than x.
>
> Ugh. One would think it is
> trivial in CL to track the min-count as a
> wrapper around (reduce #'min list)
>
> but the REDUCE spec makes it hairy to get edge cases right (where the
> input is an empty list or singleton list).
>
> (defun hen-min (list &aux (min-count 1))
> "LIST is a list of numbers. Return the MIN of the list. Second
> return value is the count of the MIN in the given LIST"
> (values (reduce (lambda (&optional a b)
> (when a
> (prog1 (min a b)
> (cond ((< b a) (setq min-count 1))
> ((= b a) (incf min-count))))))
> list)
> (if (endp list) 0 min-count)))
>
> It still reads nicer without any [???]

Hen may have fallen into the "list comprehension sytnax" in constructing
the example he posted. But this is just a tar pit, which lets you lose
focus of the problem at hand (by inventing new problems)

in common lisp HEN-MAX has been extended MAX to return a second return
value with counts. This is the simplest abstraction to construct
solutions which require counts of MIN, and is sufficient for common
lisp, without the need to invent a new language feature or inventing new
syntax.

while CL has several generator libraries (which I haven't really used
seriously yet), in plain CL Hen's motivating example above would look
like this:

(loop for x from -10 to 10
collect (* (- x 2) (- x 3)) into A
collect x into B
collect (- x 2) into C
collect (- x 3) into D
finally (return (destructuring-bind (a b c d)
(mapcar (lambda (x)
(multiple-value-list (hen-min x)))
(list a b c d))
(values
(destructuring-bind (a b c d)
(mapcar 'car (list a b c d))
`(,a (,b (,c ,d))))
(destructuring-bind (a b c d)
(mapcar 'cadr (list a b c d))
`(,a (,b (,c ,d))))))))

;; => (0 (-10 (-12 -13))),
;; (2 (1 (1 1)))

The first value returns the minimum in the "compehended invented "tuple
structure, the second value returns the counts in the same structure.

Subject: Re: How do i get multiple Min() values?
From: Nuno Silva
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 17 Jul 2024 09:58 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nunojsilva@invalid.invalid (Nuno Silva)
Newsgroups: comp.lang.lisp
Subject: Re: How do i get multiple Min() values?
Date: Wed, 17 Jul 2024 10:58:20 +0100
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <v784js$1pfad$1@dont-email.me>
References: <v6qu7m$2vg8q$1@dont-email.me> <v6rug7$35c6s$2@dont-email.me>
<20240715051340.619@kylheku.com>
<m3a5ih1gss.fsf@leonis4.robolove.meer.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Wed, 17 Jul 2024 11:58:21 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="26ecf9206ae9447ab01eeb3d3ce6102b";
logging-data="1883469"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GZx514GVxpuNnKhhqEmaO"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
Cancel-Lock: sha1:FWGsTHTI5y/V7mrmqebpK7YIAu8=
View all headers

On 2024-07-16, Madhu wrote:

> * Kaz Kylheku <20240715051340.619@kylheku.com> :
> Wrote on Mon, 15 Jul 2024 12:27:58 -0000 (UTC):
>
>> On 2024-07-12, HenHanna <HenHanna@devnull.tb> wrote:
>>>>
>>>> How do i get multiple Min() values?
>
> You just need the count of the min value. you don't really need
> "multiple min() values". right?

I'm thinking it depends on what kind of entities you are comparing, if
you are using some comparison function to determine what the multiple
minima are, isn't it possible to have multiple minima which are
different objects one might want to see as multiple values, and not
something that can be duplicated from a single copy?

Sure, you could optimize for numbers, but that'd make it less flexible
too?

--
Nuno Silva

Subject: Re: How do i get multiple Min() values?
From: B. Pym
Newsgroups: comp.lang.python, comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 15 Aug 2024 03:33 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.python,comp.lang.lisp
Subject: Re: How do i get multiple Min() values?
Date: Thu, 15 Aug 2024 03:33:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <v9jsuo$qnm3$1@dont-email.me>
References: <v6qu7m$2vg8q$1@dont-email.me> <v6tthj$3jj0a$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Date: Thu, 15 Aug 2024 05:33:46 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e5ecf5f7253603983f636ec904f7241";
logging-data="876227"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ZASZpdwBBSeo4iR7DAq8J"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:cHbua32W4R2mxon6wpunhHTmWHI=
View all headers

B. Pym wrote:

> HenHanna wrote:
>
> >
> > How do i get multiple Min() values?
> >
> > e.g. for Y = (x-2)*(x-3) for x in range(-10,10)
> > the min Y is hit twice
> >
> >
> > print( min( ((x-2)*(x-3), (x, (x-2, x-3)))
> > for x in range(-10,10) ) )
> >
> >
> >
> > is this easy in Scheme(Gauche) ?
>
> Gauche Scheme
>
> (use gauche.collection) ;; fold2
>
> (define (min-by fn lst)
> (if (null? lst)
> (values '() #f)
> (fold2
> (lambda (x best worth)
> (let ((score (fn x)))
> (cond ((< score worth) (values (list x) score))
> ((= score worth) (values (cons x best) worth))
> (#t (values best worth)))))
> (take lst 1) (fn (car lst))
> (cdr lst))))
>
> (min-by (lambda(x) (* (- x 2) (- x 3))) (lrange -10 11))
>
> ===>
> (3 2)
> 0

newLISP

(define (min-by fun lst)
(let (accum '() best 0 score 0)
(dolist (x lst)
(setf score (fun x))
(cond ((or (empty? accum) (< score best))
(setf best score)
(setf accum (list x)))
((= score best) (push x accum))))
(list accum best)))

(min-by (fn(n) (- (abs (* 10 n)))) '(0 9 2 2 -9 3))
===>
((-9 9) -90)

1

rocksolid light 0.9.8
clearnet tor