How do I get all permutations in KDB?

Viewed 88

Say I want to get:

0 0
0 1
0 2
1 0
1 1
1 2
etc

I'm to do (til 3) (,\:) til 3 but this doesn't seem to do it, giving me a type error.

What am I doing wrong?

1 Answers

cross keyword is what you are looking for

q)(til 3) cross til 3
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2

The solution to your original problem without using a keyword is:

q)raze ((til 3),/:\:) til 3
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Related