I guess that's me thinking in terms of norm ← {÷∘(+/)⍨⍵} so that I can then apply norm to whatever. But that's not the usual apl workflow, right? You just write the sequence of glyphs you need, as needed
As you can see from the 2⊃⍴ the left-side tine of a fork can be a constant, which just works as a constant function. It is in fact very common to have constants there.
E.g. you can check if an array is empty with empty←0∊⍴ or if it is a scalar with ⍬≡⍴
You can check if the arguments are co-prime with 1=∨ or get the inclusive difference with 1+-
My solution to the APL problem solving contest 1:8 is just terrible. Looking forward to the contest being over so that I can ask how on Earth to improve it. I'm currently drunk on forks.
Yes, you give the function a number as argument, and it'll return that many grades, but no two grades will ever be the same. The maximum is 18, which generates a random order of all possible grades.
It is because of ⍵?≢r which uses dyadic ? (deal). If you want independent values, use ?⍵⍴≢r which uses monadic ? (roll).
@AndréLeria If you allow duplicates: {⎕A[?⍵⍴6],¨'-' '' '+'[?⍵⍴3]}
But for no-duplicates, your solution is pretty much as good as it gets. You have an unnecessary ⌽ and you don't need the right-most parenthesis. You also already know that ≢r is 18, so no need to compute that. Finally, you can "unpack" your derived selection function {(⊂⍵?18)⌷,(6↑⎕A)∘.,'-' '' '+'} or just use brackets {(,(6↑⎕A)∘.,'-' '' '+')[⍵?18]}
@AndréLeria Not sure. It might be faster to use your approach. For allowing duplicates, that'd be {(⊂?⍵⍴18)⌷,(6↑⎕A)∘.,'-' '' '+'} or {(,(6↑⎕A)∘.,'-' '' '+')[?⍵⍴18]}