Noting that binary is the base for monadic antibase,
h=: ((= +/"1) # ]) ([: #: [: i. 2&^)
3 (0 -.@:e. (Smps -: h)&>) #\i.9 NB. a test
1
And Raul already arrived here. Can we further eliminate ]same?
Date: Sat, 31 Jul 2021 15:52:03 + (UTC)
From: "'Bo Jacoby' via Programming"
To: Pro
Alternatively, you could just use comb:
require'stats'
2 (i.@] e."1 comb) 6
1 1 0 0 0 0
1 0 1 0 0 0
1 0 0 1 0 0
1 0 0 0 1 0
1 0 0 0 0 1
0 1 1 0 0 0
0 1 0 1 0 0
0 1 0 0 1 0
0 1 0 0 0 1
0 0 1 1 0 0
0 0 1 0 1 0
0 0 1 0 0 1
0 0 0 1 1 0
0 0 0 1 0 1
0 0 0 0 1 1
Or, if you want the previous orderi
Thanks, Bo.
This variation on comb works pretty well, except it doesn't test for the
empty case, ie x = 0:
NB. these boolean verbs are quicker than multiply and add for this case
twice =: 1 & (32 b.)
or =: 23 b.
Smpscomb =: 4 : 0
k=. 2^i.>:d=.y-x
z=. <"0 k
for. i.<: x do.
z=. k or &.
Thanks to Mike!
comb=: 4 : 0
NB.*comb v combinations of size x from i.y
comb=: 3 : 0
comb~ y
:
k=. i.>:d=. y-x
z=. (d$ ,&.>/\. >:&.> z end.
3 comb 6
I need to study in order to make it do what I want. I am aware that my
programming is embarassingly inefficient.
Thanks to Raul!
2
Nice work, especially persuading 13 : to return a tacit version.
I had reached the same solution as Pascal Jasmin’s, so not worth a comment in
itself.
However, it is just about worth pointing out that the filtering approach gets
expensive for larger values of y; eg 3 Smps 20 would entail fi