Skip to content

Instantly share code, notes, and snippets.

@apb2006
Last active September 18, 2015 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apb2006/f976d881640ad3adff7d to your computer and use it in GitHub Desktop.
Save apb2006/f976d881640ad3adff7d to your computer and use it in GitHub Desktop.
generate powerset
(: 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