« first day (223 days earlier)      last day (2980 days later) » 

10:11
@LuisMendo Is this a bug or a feature?
Z@ (randperm) on the input 'asdf' provides a random permutation of the input
how ever when performed on a numerical array like [1,2,3,5,6] it just returns 1
I'm asking because of this challenge, so far I'm stuck at Y@tG=!afZ@ where this exact proplem pops up.
 
2 hours later…
12:25
@flawr It's intenteded behaviour (although I'm not totally happy with it):
Z@  random permutation
    1--3 (1 / 2);  1
    randperm (produces a row vector as output). If 3 inputs: third
    input indicates number of permutations, each on a different row.
    If first input is char it is interpreted as population (not as
    size)
As usual in MATL, this is modelled after a Matlab function: randperm, which takes a single number as input.
Sometimes it's good to have as input the population, rather than its size. But I didn't include that because then if the input is a single number, is it a (singleton) population or a population size? On the other hand, with char input there's no such confusion, so it interprets it as population.
(With nchoosek there was the same issue, and I split it in two functions (Xn, XN). Maybe I should have done this with randperm too.)
@flawr Anyway, the char input version is useful here. I think this works for 7 bytes
`Z@tG=a
It keeps permuting until no element coincides
It exploits the fact that any permutation is as good a starting point for other permutations as the input is
Hm I think that's what Martin does. Worth posting, still :-)
 
2 hours later…
14:11
@LuisMendo Feel free to post this version yourself. It is a little bit too non-deterministic for my taste, as you might theoretically very well run into a situation where the rng has a too short period :D
@LuisMendo Thanks for explaining!
 
2 hours later…
16:01
@flawr Stewie arrived at the same solution in the meantime :-)
16:35
@flawr Going back to your approach: I think you need -!A rather than =!a. And you can use Zr (randsample) directly instead of Z@. So Y@tG-!Af1ZrY) works. I think it's worth posting noting that, unlike other answers, it doesn't use rejection sampling and its running time is deterministic :-)
16:52
@LuisMendo Well please go ahead, I think this is now more your solution than mine. I like the - instead of the = (I generally like the idea of bsxfun-ing all these functions!)
@flawr No, it's your idea. It would have never occurred to me to do it that way. You can post it and say it was a joint effort (as I've seen in other answers in the past) :-)
That might be acceptable=)
bsxfunning all (most) functions was one of my main drives in creating MATL :-)
Now Matlab does that from R2016b
Really??
Perhaps I do need to get a newer version at some point=)
Yes. It feels weird, after all this time wibh bsxfun
16:55
but I think bsxfun is still available, right?
bsxnomorefun
Yes, it is. And I tend to use for clarity and backwards compatibility. But not needed anymore
@flawr :-D

« first day (223 days earlier)      last day (2980 days later) »