cjm2671
cjm2671

Reputation: 19486

How do I get all permutations in KDB?

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?

Upvotes: 1

Views: 310

Answers (1)

MurrMack
MurrMack

Reputation: 579

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

Upvotes: 4

Related Questions