q)t:(w:a
bc
d`e)
q)(t.w _ 3)[-3?-1+count t]
a
e`c
q)t2:select w,other:(t.w _ i)[-3?-1+count t] from t
'length
My end goal:
q)select from t2
w o1 o2 o3
a b c e
b d a c
c a d b
d e c a
e c d b
q)t:(w:a
bc
d`e)
q)(t.w _ 3)[-3?-1+count t]
a
e`c
q)t2:select w,other:(t.w _ i)[-3?-1+count t] from t
'length
My end goal:
a b c e
b d a c
c a d b
d e c a
e c d b
q)flip w
o1o2
o3!(enlist t.w),flip {(t.w _ x)[-3?-1+count t]}each til count t
w o1 o2 o3
a b ?c ?e
b d ?e ?a
c d ?e ?b
d c ?a ?b
e d ?c ?b
q)select w,other:{(t.w _ x)[-3?-1+count t]}'[i] from t
w other
a b c d
b d c e
c e a b
d c b a
e a c b
q)select w,o1:other[;0],o2:other[;1],o3:other[;2] from select w,other:{(t.w _ x)[-3?-1+count t]}'[i] from t
w o1 o2 o3
a c ?b ?e
b e ?a ?c
c d ?e ?b
d b ?e ?a
e a ?c ?b
t,'exec flipo1
o2`o3!flip -3?'w _/:i from t
This is great! Would you mind walking me through it?
I understand that
table,'exec
is a column join: https://code.kx.com/trac/wiki/QforMortals2/tables#Column-Join
But this one throws me for a loop
flip -3?'w _/:i from t
This makes sense: select -3?'w _/:i from t
but I don’t understand why it needs to be flipped again: select flip -3?'w _/:i from t
q)i:til 5
q)i
0 1 2 3 4
q)t.w _/:i
b c d e
a c d e
a b d e
a b c e
a b c d
q)-3?'t.w _/:i
b e d
c a e
d e a
b c e
b a c
q)flip -3?'t.w _/:i
c d b a b
d e d e a
e c e c d
q)o1
o2`o3!flip -3?'t.w _/:i
o1| b d e a b
o2| d a a e a
o3| e c d c c
o1
o2`o3!flip -3?'t.w _/:ib? c? d
d? c? e
e? a? b
c? b? a
a? c? b
q)