Maybe someone can help me with this?
I start with a list, e.g.
((0) (1 3) (1 2) (4 6) (5 7) (7 8))
and want all members of intersecting lists to appear in the same sublist:
((0) (1 2 3) (4 6) (5 7 8))
From: Drew Krause
Subject: rather simple list/set operation
Date: Tue, 3 Jan 2012 19:01:19 -0600
Drew Krause wrote:I think the problem definition is ambiguous and not clarified by the
Maybe someone can help me with this?
I start with a list, e.g.
((0) (1 3) (1 2) (4 6) (5 7) (7 8))
and want all members of intersecting lists to appear in the same sublist:
((0) (1 2 3) (4 6) (5 7 8))
Am 2024-06-07 um 20:07 schrieb Jeff Barnett:
Any idea what Krause had in mind?linked lists
On 6/7/2024 1:56 AM, W J wrote:
From: Drew Krause
Subject: rather simple list/set operation
Date: Tue, 3 Jan 2012 19:01:19 -0600
Drew Krause wrote:
Maybe someone can help me with this?
I start with a list, e.g.
((0) (1 3) (1 2) (4 6) (5 7) (7 8))
and want all members of intersecting lists to appear in the same sublist: >>>
((0) (1 2 3) (4 6) (5 7 8))
I think the problem definition is ambiguous and not clarified by the
example.
Consider the following input lists:
((0 1) (1 2) (2 3)),
((0 1) (0 2) (0 3)).
Any idea what Krause had in mind?
((0) (1 2 3) (4 6) (5 8 7))
From: Drew Krause
Subject: rather simple list/set operation
Date: Tue, 3 Jan 2012 19:01:19 -0600
Drew Krause wrote:
Maybe someone can help me with this?
I start with a list, e.g. ((0) (1 3) (1 2) (4 6) (5 7) (7 8))
and want all members of intersecting lists to appear in the same
sublist:
=> ((0) (1 2 3) (4 6) (5 7 8))
Gauche Scheme:
(use srfi-1) ; "lset-" functions
(use srfi-42) ; do-ec
(define (coalesce lists)
(define accum '())
(do-ec (:list x lists)
(receive
(miss hit)
(partition (lambda (y) (null? (lset-intersection equal? x y)))
accum)
(set! accum
(cons (apply lset-union equal? x hit) miss))))
accum)
(coalesce '((2 4) (8 9) (4 5 8)))
===>
((2 9 4 5 8))
(coalesce '((2 4) (3 9) (5 6) (2 3)))
((4 9 2 3) (5 6))
(coalesce '((0) (1 3) (1 2) (4 6) (5 7) (7 8)))
((5 7 8) (4 6) (3 1 2) (0))
(coalesce '((2 4) (3 9) (5 6) (2 3) (55 66) (0) (66 6)))
((5 55 66 6) (0) (4 9 2 3))
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 403 |
Nodes: | 16 (2 / 14) |
Uptime: | 43:36:23 |
Calls: | 8,407 |
Calls today: | 2 |
Files: | 13,171 |
Messages: | 5,905,025 |