I found this resource for tips on code-golfing (writing the shortest possible code) in APL:
(some tips are from @abrudz )
A lot of these seems kind of advanced, but still interesting to check out…
I found this resource for tips on code-golfing (writing the shortest possible code) in APL:
(some tips are from @abrudz )
A lot of these seems kind of advanced, but still interesting to check out…
This video is what got me interested in APL originally, which walks through how to code the game of life step by step in APL. Ends with super short code for the game of life and is very cool to hear the steps get talked through
This person has an excellent way of explaining things, I want to watch more videos made by them. No ceremony, no dumbing things down, just pure information. Brilliant!
Thanks for sharing!
You can find more of his works (including videos) at John Scholes - APL Wiki
Thanks for that information @abrudz , I found one of John’s talks quite interesting and right up my alley;
A Plea for simplicity.
This is great! I also like to practice code golfing problems when learning a new programming language. https://problems.tryapl.org/ has a bunch of problems from yearly APL competitions, and validates your solutions against example sets
2022 APL Problem Solving Competition is on. The competition offers cash prizes. The deadline for submission is Friday 29 July 2022 at 23:59 BST. Good luck.
Hi @abrudz, I have some trouble following the APIwiki - Dfn. I hope it is ok to ask you here.
The following example (nth root ⍺√⍵
) is not working.
The root
function works if ⍺←2
is removed.
Of course, it is expected to get “divide by zero” error when ⍺
is 0.
The documentation under “Guards” suggested that we can deal with it by adding ⍺=0:0
.
I tried the following combos; however, there all failed explicitly or silently.
Could you please advise what is the best practice to catch edge cases? Thank you in advance.
PS. I use Dyalog APL version 18 in Windows.
The problem is that the function has multiple statements ⍺←2
and ⍵*÷⍺
but what you’ve put into the notebook document is just a single statement ⍺←2 ⍵*÷⍺
=. You can separate statements with ⋄
as in root ← {⍺←2 ⋄ ⍵*÷⍺}
or use `]dinput to indicate that this notebook block defines a multiline function:
]dinput
root ← {
⍺←2
⍵*÷⍺
}
Similarly, for the function with a guard, write root ← {⍺=0:0 ⋄ ⍵*÷⍺}
or
]dinput
root ← {
⍺=0:0
⍵*÷⍺
}
We’ll look into making this automated in the future, so you can omit ]dinput
.
That would indeed be much more intuitive - thanks!
I am having fun practising APL based on the Competition questions.
Jeremy,
Could you cover the following symbols/operators in the coming sessions, please?
⌸, ⊆,⊂, ↑,↓, @, Reduce N-Wise
Why those in particular? What’s “Reduce N-Wise”?
/
covers n-wise reduce I believe. I think it is called n-wise reduce vs reduce when used with a bracket axis to specify n axis, such as the second axis in +/[2] 3 3 3 ⍴ ⍳27
.
No, N-wise Reduce is the dyadic form of Reduce, which reduces over each window of size N:
3+/3 1 4 1 5
8 6 10
Same as:
(+/3 1 4)(+/1 4 1)(+/4 1 5)
8 6 10
Because each problem in the competition has a hint for one or more primitives that could be useful in solving it, e.g.:
Hint: The Reduce N-Wise operator
Xf/Y
could help with solving this problem.
The ones listed by @Moody are the ones given in hints that you haven’t covered yet.
Hi Adam, I hope that it does not count as cheating. As a beginner, I find the Dyalog documentation is a bit hard to understand. I just want Jeremy to go through them as usual. Hopefully, other fastai folks with more programming experience may join the competition as well.
Not cheating at all. The Dyalog documentation is very much a reference for those that already know the language. You might find APL Wiki’s articles more pedagogical. E.g. see Windowed Reduce - APL Wiki
Hey @Moody
I also have been having lots of fun attempting the 2022 APL Problem Solving Competition questions. Working on the Phase 1 problem set has been very enlightening. I have learned so much while struggling with these problems.
After the competition is over I would like to compare our solutions
Same here. My current solutions are very hacky. Hopefully, I can improve them further when I learn more glyphs.
I also work on Dyalog Course and try to solve simpler problems. The answers are under the collapsed headings. So, it is very beginner friendly.