Re: Lisp problem to solve

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Lisp problem to solve
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 29. Aug 2024, 08:23:13
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vap44d$3s8t5$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
John Thingstad wrote:

Pn++ Tue, 20 Nov 2007 23:59:24 +0100, skrev Mark Tarver
 
 
On 20 Nov, 14:48, ryan.dufra...@gmail.com wrote:
You are given a list of transactions along with the
profits from the transactions. Write code that will return the
transaction with the maximum profit. If many transactions have the
same and maximusm profit, the code can return any of these. For
example,
given ((T1 20) (T2 88) (T3 188) (T4 99) (T5 66)), the code should.
return T3.
>
I am looking for code or pseudocode.
>
(SETQ *LIST* '((T1 20) (T2 88) (T3 188) (T4 99) (T5 66)))
>
Shortest solution is 1 line.
>
(FIRST (FIRST (SORT *LIST* (FUNCTION (LAMBDA (X Y) (> (SECOND X)
(SECOND Y)))))))
>
Mark
>
 
or (caar (sort *list* #'> :key #'second))

Gauche Scheme:

(define List '((T1 20) (T2 88) (T3 188) (T4 99) (T5 66)))

(caar (sort List > last))

  ===>
T3

Date Sujet#  Auteur
29 Aug 24 o Re: Lisp problem to solve1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal