« first day (2165 days earlier)      last day (482 days later) » 

1:00 PM
Welcome to APL Quest 2017-8! Today's quest is Be the First 1:
> Write a dfn that takes a Boolean vector or scalar and “turns off” all the 1s after the first 1.
This should be quick.
 
<\
:)
 
That's all folks!
What if you couldn't use that?
 
tried as alternative using ⊃⍸ for finding fist postition of the 1
 
Ah yes, good approach.
 
and than inserting it into vector of same length filled woth 0's
 
1:02 PM
We had an intern add old problem sets to the automated site. He was quite new to APL, so you've got to give him A for effort on {⍵{(↑⍵↑⍺),((≢⍺)-⍵)⍴0}+/⍸(⍋⍋⍵)=1+(≢⍵)-+/⍵}
 
wow
 
@Richard Will have issues with arguments that have no 1.
 
yes true
 
Huh, there's a missing test case.
 
single 1?
 
1:05 PM
@Adám ((⊢>¯1↓0,⊢)∨\)
 
@Richard Yes.
@dzaima That's very good, but using a different Boolean scan…
 
@dzaima (translating from BQN ≠⟜»∨`)
@Adám but it's one that doesn't use the left-to-right-to-left-ness of APLs scan
 
True.
 
⍳∘≢=⍳∘1
 
Fails on scalars, but otherwise good.
Industrial strength solution: ⍎'1(.*)'⎕R{'1 ',2↓'0 '⍴⍨⊃⍵.Lengths}⍤⍕,',⍬'⍨
@Richard Huh, the reference solution is even wrong!
 
1:13 PM
⊃⊖{⍵}⌸
instead of ⊃⍸
for the first 1
 
Fun. {⍵} is btw.
@Richard Fails on 1 0
 
I stilll don't fully understand {⍺⍵} just left from an operator. I can use it but don't understand the logic.
 
@dzaima Fixed: {r⊣(,r)←(⍳≢⍵)=1⍳⍨,r←⍵}
@Richard {⍺⍵} is no different from any other function. It is the same as ,⍥⊂
 
The ⍺ and ⍵ magically are retreived from the operator on the right?
 
Not sure what you're asking.
 
1:18 PM
Where do the ⍺ ⍵ get their values from?
{⍺⍵}⌸
 
@Adám ⍴⍴⍳∘≢=1⍳⍨, if you really want to support the useless case
 
D'oh. Yes.
@Richard Every operator is different. Monadic f⌸ applies f once for each unique major cell in the argument. The left argument given to f is the unique major cell, and the right argument is the list of indices where that cell occurs in the argument.
 
@Richard where does {⍺⍵}¨ get & from? where does ∘.{⍺⍵} get their & from? answer: operators can just decide to give whatever arguments they want to their operands
 
I should see {⍺⍵} as a function of course which is input for the operand
 
Indeed. Although we tend to say "operands" for operator inputs.
 
1:25 PM
and that explains using ⊢ intead of {⍵}, both are functions or operands for the operator
 
Exactly.
 
and the right operand of ⌸ is not a function but a matrix.
 
is a monadic operator, it has no right operand.
@147pm Welcome to the APL Orchard. Did you solve your keyboard problem?
 
oh yes, so the operator with its left operand results in a new derived functon which takes an aray as its right argument
 
That's correct.
And on that note, I think we can end this week's episode. See you next week for 2017-9: Double Trouble.
 
1:30 PM
thanks, till next week
 
 
6 hours later…
7:24 PM
0
Q: I need to most efficiently insert a number in a maintained large sorted variable. Is there a better method than test1?

creaturaltest1 is quite a bit faster vs test2 which is just to append a variable then resort. q←⍳1000000 ⋄ q←10 9 8 7 6 5 4 3 2,q ⍝q is kept sorted test1←{ y←⍺(⍳∘1≤)⍵ ⍝ very fast (y↑⍺),⍵,(y↓⍺) ⍝ is there a tacit version here and without copying? } 10↑q test1 6 10 9 8 7 6 6 5 4 3 2 cmpx 'q test1 6' 3.2E...

 
 
2 hours later…
9:15 PM
In SETL, the conventional program for the factorial of n is */[1..n], according to the Wikipedia page. But APL isn't listed as an influence, nor any APL derivative. It's not mentioned anywhere on the page, actually. Should it be?
SETL (SET Language) is a very high-level programming language based on the mathematical theory of sets. It was originally developed by (Jack) Jacob T. Schwartz at the New York University (NYU) Courant Institute of Mathematical Sciences in the late 1960s. == Design == SETL provides two basic aggregate data types: unordered sets, and sequences (the latter also called tuples). The elements of sets and tuples can be of any arbitrary type, including sets and tuples themselves. Maps are provided as sets of pairs (i.e., tuples of length 2) and can have arbitrary domain and range types. Primitiv...
 

« first day (2165 days earlier)      last day (482 days later) »