Skip to content

Instantly share code, notes, and snippets.

@dardo82
Last active January 26, 2016 03:44
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 dardo82/1377bba81076358084da to your computer and use it in GitHub Desktop.
Save dardo82/1377bba81076358084da to your computer and use it in GitHub Desktop.
Operations with sets
#!/bin/zsh
join -1 2 -2 2 <(echo ${${1//,/\\n}//({|})/}) <(echo ${${2//,/\\n}//({|})/})|gsed 's/^ /(/;s/ /,/;s/$/)/;s/\n/,/'|gsed -z 's/\n/,/g;s/^/{/;s/,$/}\n/'
#!/bin/zsh
S=$(eval echo\ "\{\,-$1-\}")
P=$(eval echo\ "{${S// /}}")
echo {${${P//(--| )/,}//-/}}
@dardo82
Copy link
Author

dardo82 commented Sep 30, 2015

SET1='{a,b,c}'; SET2='{1,2,3}'
./power-set.sh $SET1
./power-set.sh $SET2
./cart-prod.sh $SET1 $SET2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment