« first day (2389 days earlier)      last day (483 days later) » 

10:28
@rak1507 Nice.
 
4 hours later…
14:51
Welcome to APL Quest 2020-10! Today's quest is Stacking it Up:
> Write a function that takes as its right argument a vector of simple arrays of rank 2 or less (scalar, vector, or matrix). Each simple array will consist of either non-negative integers or printable ASCII characters. The function must return a simple character array that displays identically to what {⎕←⍵}¨ displays when applied to the right argument.
There are so many approaches to this one. Some lead to very brief and simple solutions, others to… well not that.
{↑⊃,/{↓1/⍕⍵}¨⍵}
Nice one.
Interesting that you did 1/⍕ to ensure that character scalars would become vectors. Didn't think of that.
I had the similar {↑⊃,/↓∘⍕¨1/¨⍵} which un-scalarises everything before
{,¨↓⍕⍵} also seems to work for the inner dfn
yes, same thing.
Btw, you can make your inner dfn tacit: (↓1/⍕)¨
Note that / doesn't give you problems here, because there's an array on its left.
Nice, thanks!
Always nice when / just works in tacit
15:06
You can even use a non-train derived function: {↑⊃,/1↓⍤/∘⍕¨⍵} but that's probably harder to read, at least harder than {↑⊃,/↓¨1/∘⍕¨⍵}
OK, but all of these rely on splitting each array into lines, then joining the lines and mixing. Let's try some other approaches.
A completely different approach is to create a simple LF or CR-delimited vector.
Wanna give it a go, or shall I reveal my solution?
I can try
@RubenVerg had such a solution after we finished last week. I'll hold off on posting here then.
I would still have to Split the Formatted arrays, right?
No, you can add a line break to the right of a matrix.
Ah
{¯1↓∊((⎕UCS 10),⍨1/⍕)¨⍵} ?
15:14
yes, that works. Can probably be simplified a bit, though.
For instance, you don't need the 1/ because you're concatenating to it anyway.
Ah yes, that's nice
If you concatenate on the left and drop from the head, you avoid the (and the ¯).
And then you don't even need a train anymore; you can just preprocess the right-argument to , with
{1↓∊(⎕UCS 10),∘⍕¨⍵}
Beauty, isn't it?
Let's do a modification on the first approach.
Would be even nicer if newline took fewer characters :)
15:21
Technically, you can write ⎕TC[2] but please don't.
We can simply stack the arrays and format that. Since the result is nested, the default display form is adding a column of spaces to the left and far right. Then we can simply strip those columns off!
Want to try it, or shall I show?
Oh, forgot to reveal:
Aug 4 at 16:19, by RubenVerg
{1↓∊⎕tc[2],¨⍕¨⍵} then
Huh, so ⎕TC is just a constant (backspace, linefeed, newline)
Let me try
@rabbitgrowth Yes, but it is a legacy feature, and subject to ⎕ML
@Adám oh no i did bad things
do I go to apl jail?
No, "go to" is considered harmful.
→apl_jail
15:30
:)
Almost works: {1↓⍤1⍕⍪1/¨⍵}
You forgot to drop the rightmost column.
{(¯1↓1∘↓)⍤1⍕⍪1/¨⍵}
or maybe {⍉¯1↓1↓⍉⍕⍪1/¨⍵}
@RubenVerg ⎕DL 604800
@rabbitgrowth Yes, any of those. The last one is what I had written down.
@Adám one whole week?? judge please reconsider the case
Have you had enough, or do you want more (stranger) approaches?
15:33
oh please I want all the 2000-character solutions
More stranger approaches! More stranger approaches!
OK, but btw, ⎕FMT is (for arrays without control chars) just like but always returns a matrix. Convenient here.
So, one (crazy) approach is to format each array as a matrix, then widen them all until the width of the widest one, then stack them. Wanna try or shall I just show how?
Sounds doable, let me try...
An even crazier one is to automatically widen the matrices by just mixing them. However, this also lengthens them by adding blank rows until they have the same height. Then you need a way to identify which rows were added, so you can remove them. And no, you cannot just remove all-blank rows, as those are valid parts of input.
@Adám {⊃⍪/⍉¨(⊢↑¨⍨⌈/⍤(≢¨))⍉⍤⎕fmt¨⍵}?
I'm sure this could be made much neater but probably not worth it :)
15:41
Yup, that looks like it would work. I had ⊃⍤(⍪⌿(⌈/≢∘⍉¨)↑⍤1¨⊢)⎕FMT¨
Just wrote down {{⍉⊃,/⍵↑⍨¨⌈/≢¨⍵}⍉⍤⎕FMT¨⍵}
Same thing, really.
And if we want to use rather than ⎕FMT?
I don't know, would you need some way to force everything into a matrix?
Yes, but that's easy enough: just add leading axes of length 1 until you have two axes.
@Adám ⊢⍴⍨¯2↑1 1,⍴ I guess?
I'm sure there's an easier way
15:45
No, that's exactly what I have. I do want an extension to so it can do it easier, though.
oh yay another "thing adám wants in apl" segment
what'd that be?
0 0↓a would make a into a matrix if it isn't already rank 2 or higher.
This already works when a is a scalar. I just want to extend it to all arrays.
cool
@Adám tried this for a little, looks like way too much work
oh wait I had an idea
OK, I'll hold off on telling you how I did it.
I was thinking we could force the prototype to be something else so that we can detect it
by like appending a row of zeros or whatever
15:52
Ah, that's basically how I did it.
But you don't need to append, you can substitute the data altogether.
{' '@(0=⊢)⊢⊃⍪/({⍵⌿⍨~∧/⍵=0})⍤↑¨↓↓↑(0⍪⎕fmt)¨⍵}
@Adám oh right yea
can you just put like 1's everywhere?
I guess that might work
Yes you can. I had {(,↑1⍨⍤1¨f)⌿,[⍳2]↑f←⎕FMT¨⍵}
,[⍳2] looks incredibly cursed
Yes, I want to make that a primitive; monadic
All it does is demote the array (lessen the rank by 1) by combining the two leading axes (essentially replacing their entries in the shape by their product).
Anyway, the critical part is 1⍨⍤1¨f where we replace each row by a scalar 1 such that will pad with 0s and the result (after ravelling) is a vector.
oh, each row, not each character
even nicer
15:58
Thanks. Still cursed, though.
oh yea definitely very cursed
please tell me there are even weirder solutions
Well, one I didn't implement is based on {⎕←⍵}¨
Can you guess how?
I'm not sure I know Dyalog-specific stuff enough to know if you can like, redirect stdout or whatever
oh but this is designed as a phase 1 problem so it's sandboxed right?
The actual competition was sandboxed. But the checker used on problems.tryapl.org isn't…
Amazingly, this passes: {l←⎕SE.Log ⋄ {⎕←⍵}¨⍵ ⋄ ↑¯1↓(1+≢l)↓⎕SE.Log}
Ooh, we can even write ⎕SE.{l←Log ⋄ {⎕←⍵}¨⍵ ⋄ ↑¯1↓(1+≢l)↓Log}
@Adám this is interesting and yet the ugliest solution i can imagine
@Adám aaaand this is even worse :)
16:05
hehe, time to stop, methinks.
Hey, we finished all of 2020. Next see you next week for 2021-1: Are You a Bacteria?!
@Adám early 100×≢÷⍨1⊥∊∘'CG', once again in the hope I'll still be able to make it

« first day (2389 days earlier)      last day (483 days later) »