0

in KDB/Q, how do I generate all combinations given an alphabet universe (doesn't have to be string, could be like a list of numbers) for a given size n?

What I am looking for is similar to this in python, but in q. How to generate all possible strings in python?

Matt Frank
  • 177
  • 6

1 Answers1

4

Using cross would be the easiest method:

q){y(x cross)/x}["ABC";1]
"AA"
"AB"
"AC"
"BA"
"BB"
"BC"
"CA"
"CB"
"CC"

q){y(x cross)/x}["ABC";2]
"AAA"
"AAB"
"AAC"
...
terrylynch
  • 11,844
  • 13
  • 21