Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You worry too much about your job. Stop it. You are not paid enough to worry.


comp / comp.lang.lisp / Re: Remove part of a list

SubjectAuthor
* Re: Remove part of a listB. Pym
`- Re: Remove part of a listKaz Kylheku

1
Subject: Re: Remove part of a list
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 20 Jul 2024 16:23 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Remove part of a list
Date: Sat, 20 Jul 2024 16:23:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <v7go9m$3k0lk$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 20 Jul 2024 18:23:20 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2096651e3c3bc178b9d3b31ef9fd0f97";
logging-data="3801780"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MO+vnUyCOyhDDzRDJ5cB8"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:DKD9K1PLL1ZBydaUhPPnpJRVW2M=
View all headers

> > I have this list = '((8 2) (8 3) (8 4) (7 4) (6 4) (5 4) (4 4)
> > (4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) (6 4) (7 4) (8 4)
> > (8 5) (9 5) (10 5))
> >
> > And i want to remove the part os list that begin in '(8 4) to
> > the '(8 4)..
> >
> > The result sould be this: = '((8 2) (8 3) (8 4) (8 5) (9 5) (10 5))
>
> It looks as if the resulting sequence is the longest subsequence of
> the original sequence, in which the sums of the value pairs are
> strictly increasing.
>
>
> > Can anyone help me?
>
> Maybe this?
>
> (defun strictly-increasing (input-pair-list)
> (loop with max = nil
> for pair in input-pair-list
> for pair-value = (apply #'+ pair)
> when (or (null max) (> pair-value max))
> collect pair and
> do (setf max pair-value))))

Testing in SBCL:

(defun strictly-increasing (input-pair-list)
(loop with max = nil
for pair in input-pair-list
for pair-value = (apply #'+ pair)
when (or (null max) (> pair-value max))
collect pair and
do (setf max pair-value))))

STRICTLY-INCREASING
* debugger invoked on a SB-INT:SIMPLE-READER-ERROR in thread
#<THREAD "main thread" RUNNING {23EAC1B9}>:
unmatched close parenthesis

(strictly-increasing
'((8 2) (8 3) (8 4) (7 4) (6 4) (5 4) (4 4)
(4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) (6 4) (7 4) (8 4)
(8 5) (9 5) (10 5)))
===>
((8 2) (8 3) (8 4) (8 5) (9 5) (10 5))

Gauche Scheme

(define (strictly-increasing couples)
(let1 n #f
(filter
(^c (let1 sum (apply + c)
(and (or (not n) (> sum n)) (set! n sum))))
couples)))

(strictly-increasing
'((8 2) (8 3) (8 4) (7 4) (6 4) (5 4) (4 4)
(4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) (6 4) (7 4) (8 4)
(8 5) (9 5) (10 5)))

===>
((8 2) (8 3) (8 4) (8 5) (9 5) (10 5))

Subject: Re: Remove part of a list
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 20 Jul 2024 21:07 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Remove part of a list
Date: Sat, 20 Jul 2024 21:07:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 88
Message-ID: <20240720135844.167@kylheku.com>
References: <v7go9m$3k0lk$1@dont-email.me>
Injection-Date: Sat, 20 Jul 2024 23:07:24 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="375d3b1dd7d9ed927a0adbd62d6a68a5";
logging-data="3896594"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dS8yc0xpnoyg0t4ZezHWHfiVkiC8G5Qk="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:mJyAnP8jCSvXwMPRH6CN8McDzFw=
View all headers

On 2024-07-20, B. Pym <Nobody447095@here-nor-there.org> wrote:
>> > I have this list = '((8 2) (8 3) (8 4) (7 4) (6 4) (5 4) (4 4)
>> > (4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) (6 4) (7 4) (8 4)
>> > (8 5) (9 5) (10 5))
>> >
>> > And i want to remove the part os list that begin in '(8 4) to
>> > the '(8 4)..
>> >
>> > The result sould be this: = '((8 2) (8 3) (8 4) (8 5) (9 5) (10 5))
>>
>> It looks as if the resulting sequence is the longest subsequence of
>> the original sequence, in which the sums of the value pairs are
>> strictly increasing.
>>
>>
>> > Can anyone help me?
>>
>> Maybe this?
>>
>> (defun strictly-increasing (input-pair-list)
>> (loop with max = nil
>> for pair in input-pair-list
>> for pair-value = (apply #'+ pair)
>> when (or (null max) (> pair-value max))
>> collect pair and
>> do (setf max pair-value))))
>
> Testing in SBCL:
>
> (defun strictly-increasing (input-pair-list)
> (loop with max = nil
> for pair in input-pair-list
> for pair-value = (apply #'+ pair)
> when (or (null max) (> pair-value max))
> collect pair and
> do (setf max pair-value))))
>
> STRICTLY-INCREASING
> *
> debugger invoked on a SB-INT:SIMPLE-READER-ERROR in thread
> #<THREAD "main thread" RUNNING {23EAC1B9}>:
> unmatched close parenthesis
>
> (strictly-increasing
> '((8 2) (8 3) (8 4) (7 4) (6 4) (5 4) (4 4)
> (4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) (6 4) (7 4) (8 4)
> (8 5) (9 5) (10 5)))
> ===>
> ((8 2) (8 3) (8 4) (8 5) (9 5) (10 5))
>
> Gauche Scheme
>
> (define (strictly-increasing couples)
> (let1 n #f
> (filter
> (^c (let1 sum (apply + c)
> (and (or (not n) (> sum n)) (set! n sum))))
> couples)))
>
> (strictly-increasing
> '((8 2) (8 3) (8 4) (7 4) (6 4) (5 4) (4 4)
> (4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) (6 4) (7 4) (8 4)
> (8 5) (9 5) (10 5)))
>
> ===>
> ((8 2) (8 3) (8 4) (8 5) (9 5) (10 5))

Simple pop in a loop and conditionally collect.

1> (defun strictly-increasing (lists)
(build (iflet ((list (pop lists)))
(let ((val (sum list)))
(add list)
(whilet ((list (pop lists)))
(whena (> (sum list) val)
(set val it)
(add list)))))))
strictly-increasing
2> (strictly-increasing
'((8 2) (8 3) (8 4) (7 4) (6 4) (5 4) (4 4)
(4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) (6 4) (7 4) (8 4)
(8 5) (9 5) (10 5)))
((8 2) (8 3) (8 4) (8 5) (9 5) (10 5))

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

1

rocksolid light 0.9.8
clearnet tor