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))))
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))
(defun strictly-increasing (lists)(build (iflet ((list (pop lists)))
(strictly-increasing'((8 2) (8 3) (8 4) (7 4) (6 4) (5 4) (4 4)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 403 |
Nodes: | 16 (2 / 14) |
Uptime: | 44:09:39 |
Calls: | 8,407 |
Calls today: | 2 |
Files: | 13,171 |
Messages: | 5,905,028 |