[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

All combinations from a sequence

Subject: All combinations from a sequence
From: "Michael Müller-Hillebrand mmh@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 30 Sep 2021 14:20:04 -0000
 All combinations from a sequence
Good afternoon,

I have a sequence of items and I need all combinations (not permutations) in
all possible lengths.

I saw what I want described as "powerset" in the Python docs:
powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)

In XPath notation and based on strings:

my:powerset(('A','B','C','D'))

This sequence of 4 items should result in a sequence of 16 strings (order not
important) representing all possible combinations: 'ABCD', 'ABC', 'ABD',
'ACD', 'AB', 'AC', 'AD', 'A', 'BCD', 'BC', 'BD', 'B', 'CD', 'C', 'D', ''

Or more general, the result could be an array of sequences.

To get this as a solution in XSLT/XPath I am currently fiddling around with a
recursive function including head() and tail() and count() but I have the
impression I am overcomplicating things.

I am wondering, if this is a use case for fold-left() or if I should rather
think of a filter that drops 0, 1, 2 or 3 items from the sequence. Or is there
a well-known algorithm with a cool name?

Any hints are, as always, very welcome, thanks a lot,

- Michael

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.