Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "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: References: 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= Bytes: 1802 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