Last active
September 18, 2015 15:43
-
-
Save apb2006/f976d881640ad3adff7d to your computer and use it in GitHub Desktop.
generate powerset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: let $combs:=[(),1,2,3,(1,2),(2,3),(1,3),(1,2,3)] :) | |
declare function local:powerset($items as item()* ) | |
as array(*){ | |
if (count($items)=0) then [()] | |
else let $x:=local:powerset(tail($items)) | |
return array:join(($x, | |
array:for-each($x,function($v){head($items),$v})) | |
) | |
}; | |
local:powerset(1 to 3) =>array:for-each(count#1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment