« first day (2592 days earlier)      last day (55 days later) » 

9:37 AM
@user173046 Hi Mustafa Dertligarip, if you want to participate here, please email access@apl.chat
 
9:58 AM
@Richard How about making good explicit versions of tacit APLcart entries?
 
 
2 hours later…
11:54 AM
can't make it to today's quest, and also I forgot to make a solution, so here's the one I had for the contest: {⍉⍵⌷⍨⊂(⌈⌿⌊⊢-¯1*⊢)⍳≢⍵}⍉, there's probably a much simpler way but this one was the first I came up with
 
12:34 PM
How can I make a 20 sized array containing a copy of a single function, fun, for each element?
If I say funs ← 21⍴fun
it does something strange.
 
12:57 PM
@NeRoboto It is doable, but awkward. I'd rather you say what you need it for, as there's likely a better way. Anyway, (21⍴⎕NS'fun').fun does the trick.
Welcome to APL Quest, 2023-9! Today's quest is Flipping Pairs:
> Write a function that:
• takes a non-empty non-scalar array right argument
• returns an array of the same shape as the argument, but with pairs of elements along the last axis “flipped”. If the array has an odd number of elements in the last axis, leave the last element unchanged.
 
I am not finished, so no working solution. I can however show what I was working on
{s←⍴⍵ ⋄s ⍴(⌽⊢⌺(⍪2 2))⍤2⊢⍵}
 
Aha, I also tried something like that, but it gives trouble when there's an odd number of columns.
 
yes that is one problem indeed
 
Why ⍤2 and not ⍤1?
 
isn't ⍤1 working on the wrong axis?
I am not realy familiar yet with rank
 
1:03 PM
⍤1 means "on the rows", i.e. the last axis, and that's the one we want.
 
ok!
 
Thank you, in the spirit of learning less awkward code, I and trying to write a vm for this puzzle https://github.com/Aneurysm9/vm_challenge/blob/main/arch-spec

I thought I could have an array of functions representing my operations. Then I could index the relevant function with and opcode I pull straight from memory. What would a better way be?
 
1 means rows because rows are vector, i.e. have rank (!) 1.
@NeRoboto Let's get back to that as soon as this chat event is over. You're welcome to participate.
 
And ⍤2 is a complete matrix?
 
Yes, it'll apply the function to matrices (if the argument has rank 2 or more).
 
1:05 PM
I thougtt the 2nd axis. Clear, thanks
 
And ⌺(⍪2 2) would then group pairs of rows.
Then you do a reshape to get back to the original shape, since increases the rank by 1. But all that really happens is that the rows (vectors) become matrices, so we can just ravel them, i.e. ,⍤1 or even combine the ravel with the stencil (,⊢⌺(⍪2 2))⍤1
      (,⊢⌺(⍪2 2))⍤1⍳10
1 2 3 4 5 6 7 8 9 10
      (,⌽⍤⊢⌺(⍪2 2))⍤1⍳10
2 1 4 3 6 5 8 7 10 9
Now, the problem shows up with a short argument:
      (,⌽⍤⊢⌺(⍪2 2))⍤1⍳9
2 1 4 3 6 5 8 7
How might we fix this (i.e. append the missing column)?
 
just copy/append the last column
 
      ((,⌽⍤⊢⌺(⍪2 2))⍤1,⊢/)⍳9
2 1 4 3 6 5 8 7 9
      ((,⌽⍤⊢⌺(⍪2 2))⍤1,⊢/)⍳10
2 1 4 3 6 5 8 7 10 9 10
 
and the reshape will drop it automaticly at the end
 
No, not reshape, as it ravels all elements, so it'll shift everything around on args of rank 2 or more.
But close.
 
1:11 PM
ah yes, the even ones now turn out te be uneven :) Shifting problems
 
If we ravel inside the ()⍤1 then we don't need a reshape either. Our problem is now that the last axis can be too long (when it has even length). All we need to do now is to chop it down to the original length.
Hint: We can chop all the leading axes down to their original length too, since that'll be a no-op for those.
 
(≢⊢)↑
 
Yes, exactly! Though the fn is monadic, so no need for (⊢)
 
no
yes exactly
 
Then has to apply to the row's length too, i.e. be inside the ()⍤1. Want to put it all together?
Meanwhile, there are a few other approaches, including
1 hour ago, by RubenVerg
can't make it to today's quest, and also I forgot to make a solution, so here's the one I had for the contest: {⍉⍵⌷⍨⊂(⌈⌿⌊⊢-¯1*⊢)⍳≢⍵}⍉, there's probably a much simpler way but this one was the first I came up with
 
1:21 PM
@Adám how does this one return the output to the original shape?
@Adám trying...
 
{⊃,/⌽¨⍵⊂⍨1 0⍴⍨⍴⍵}⍤1
Nested, though
 
@Richard It transposes, does a shape-preserving transformation (permutation), and transposes back; monadic is self-inverse. However, the transposing is unnecessary, as one can just work on the rows with {⍵⌷⍨⊂(⌈⌿⌊⊢-¯1*⊢)⍳≢⍵}⍤1 or even {⍵[(⌈⌿⌊⊢-¯1*⊢)⍳≢⍵]}⍤1
@rabbitgrowth Right, that's another approach. Surprisingly, you can actually exploit 's strange definition on high-rank arrays here, to avoid ⍤1. Can you see how?
 
yes, but not doing a ravel first before the transpose (⍉,)
 
Oh, that's a gramatical comma "," not an APL ravel "," :-)
 
:) :)
 
1:29 PM
I tend to skip punctuation that's adjacent to inline APL code, if at all ambiguous.
 
@Adám {⊃,/⌽¨⍵⊂⍨1 0⍴⍨⊃⌽⍴⍵}?
 
(It is, however, OK to add a "." after ⍤1 since ⍤1. would work just fine.)
@rabbitgrowth Yes. Nice, eh? You can write ⊃⌽⍴ as ≢⍉ if you're golfing.
@Richard Want help?
 
think so. Using ≡ refers to the wrong argument inside the ()
 
Meanwhile, the last notable approach is to use or
@Richard ?
 
≢↑
 
1:35 PM
Right.
 
it refers to the too long vector
 
We have ((,⌽⍤⊢⌺(⍪2 2)),⊢/)⍤1 and inside that outermost paren that has ⍤1 then refers to the length of the last axis of the original argument.
 
(≢↑(,⌽⍤⊢⌺(⍪2 2)),⊢/)⍤1
 
You got it!
But we could also take along all axes: ⍴↑((,⌽⍤⊢⌺(⍪2 2)),⊢/)⍤1
And we could even make the concatenation on all rows at once: ⍴↑(,⌽⍤⊢⌺(⍪2 2))⍤1,⊢/
 
nice
 
1:42 PM
I think we could construct a right operand to such that we don't need ⍤1 but it'll be awkward.
 
Trying to figure out how to turn 5 into 2 1 4 3 5 with Grade. ⌽⍤⍒⊢↑2/⍳, I guess?
 
That works, but there are ways to do it without generating double the data.
 
⌽⍤⍒⍤⌈2÷⍨⍳?
 
Sure, but now you're wasting time on floats.
 
but realy out of the box!
 
1:48 PM
⌽⍤⍒⍳+2|⍳?
I feel like I'm missing something obvious
 
Yes, that's good, but can you avoid the reversal by using instead?
Even 2|⍳ is a bit wasteful, since no modulus computation is needed to know you get 1 0 1 0
@rabbitgrowth Need a hint?
 
yes please - trying to work this one out
 
Something like ⍋⍳+1 ¯1⍴⍨⊢? But then the isn't really doing that much
 
Yeah, that'd work too. ends up doing the pair-reversal — that's what we're after!
Instead of +1 and -1 you can also do +2 and +0
OK, now to put the whole thing together.
We can go row-wise: {⍵[(⍋⍳+⍴∘2 0)≢⍵]}⍤1
Or index the whole array: {⍵⌷⍤1⍨⊂(⍋⍳+⍴∘2 0)⊃⌽⍴⍵}
Or *shudders* use bracket axis with squad indexing: {⍵⌷[≢⍴⍵]⍨⊂(⍋⍳+⍴∘2 0)⊃⌽⍴⍵}
Watch the upcoming video for a performance comparison of these solutions.
 
2:05 PM
@Adám Would you be able to use select for this one? Or would the ⍤1 get in the way?
 
@Silas Yes, that'd work. It'd be ⊇⍤1⍨
 
Ah, ⍴∘2 0 is nice. Missed the chance to use there
 
We've been at this for over an hour, so I'll quit now. Feel free to continue. See you next week for the last one, 2023-10: Partition with a Twist!
@NeRoboto The normal thing is to just use a guard or case for each, and implement them in-place. You could also use the opcode to pick from a list of names ('halt' 'set' 'push'…) that you've defined, and then do (⍎opcode⊃names)arg to call the relevant function.
You can see an example here of using a dfn guard per op.
 
2:24 PM
@Adám I see. Thanks.
 
2:50 PM
One day I will understand the conversation you just had above.
 
3:02 PM
@NeRoboto I hope to publish a fully explained video based on it, next week.
 
3:49 PM
@Adám Where do the videos get published?
 
4:14 PM
@NeRoboto YouTube, but I link to them here and on APL Wiki.
 
4:28 PM
Ok, cool.
 
4:44 PM
I'm trying to get some bitwise operation's going but for some reason I can't get these examples to work:
https://aplcart.info?q=bitwise

2{⍉2⊥∧/2⊥⍣¯1⍉⍺,[0.5]⍵}7

gives the following error for instance
RANK ERROR: Invalid axis
2{⍉2⊥∧/2⊥⍣¯1⍉⍺,[0.5]⍵}7

Am I using it wrong?
 
Have you coppied incorrectly? Both those expressions give me 2
If from removing the ⍉ then probably want to insert a tack (⊢) between the ¯1 and the ⍺
 
I haven't copied it wrong since the one I pasted here comes from my session. I just started a new session and tried it and it works. Could I have somehow overloaded one of the functions in there during all my tinkering?
 
Shouldn't have been able to, no - must've just got into an odd state somehow...
 
So bizarre.
 
 
4 hours later…
9:07 PM
@NeRoboto Could be your ⎕io-setting. 2,[0.5]7 gives a RANK ERROR if you set ⎕io←0.
 
 
3 hours later…
11:40 PM
@Finn Oops. That would have been it. Well noticed.
 

« first day (2592 days earlier)      last day (55 days later) »