Skip to content

Instantly share code, notes, and snippets.

@isaiah-perumalla
Last active November 6, 2019 20:10
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 isaiah-perumalla/e5ee11fc4124e4a2b0d790c7502c1eef to your computer and use it in GitHub Desktop.
Save isaiah-perumalla/e5ee11fc4124e4a2b0d790c7502c1eef to your computer and use it in GitHub Desktop.
some q functions
//function return all subset of a list
sset: {[xs] (enlist ()) {x, (y,) each x }/ xs}
//or using the map each right /:
sset: {[xs] (enlist ()) {x, y ,/: x }/ xs}
//q)sset (1; 2; 3;`a)
()
,1
,2
2 1
,3
3 1
3 2
3 2 1
,`a
(`a;1)
(`a;2)
(`a;2;1)
(`a;3)
(`a;3;1)
(`a;3;2)
(`a;3;2;1)
//fibonacci
fib: {[n] last n {(-1#x),(sum x)}/ (0 1)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment