[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
exercise 2019/01
From: |
Otto Diesenbacher-Reinmüller |
Subject: |
exercise 2019/01 |
Date: |
Sat, 11 Apr 2020 23:02:39 +0200 |
User-agent: |
mu4e 1.0; emacs 28.0.50 |
Hi APLers!
as I had a look into the archives, it seems ok, to post non bugs and
other topics not closely related to gnu-apl, but APL in general (for
sure, utilizing gnu-apl)? If my following post is offtopic please
excuse, and please let me know, where would be right place to discuss.
So - i am quite new to APL, my road to APL? Some weeks ago, being a
hobbyist/partly professional Common Lisper, I stumpled upon April
(https://github.com/phantomics/april) and was fascinated by
APL. Always hungry for /something/ to get rid of Excel, I am starting
to explore the world of arrays ;).
Having browsed through "Mastering Dyalog APL"(Legrand) and "APL_ The
Language and Its Usage"(Polivka/Pakin), to get some experience, I am
trying to solve (the easy parts) of the APL Dyalog Problem Solving
Competition (https://www.dyalog.com/student-competition.htm).
I would like to share my experience, discuss the obstacles I
encounter, and especially get some advice/hints from you, the
experienced APLers! Perhaps this will lead to some blog-posts...
Let's start with the first one:
1 chunk monkey
(https://www.dyalog.com/uploads/files/student_competition/2019_problems_phase1.pdf)
"Write a function that, given a scalar or vector as the right argument
and a positive (>0)integer chunk size n as the left argument, breaks
the array's items up into chunks of sizen. If the number of elements
in the array is not evenly divisible by n, then the last chunkwill
have fewer than n elements. Hint: The partitioned enclose function ⊂
could be helpful for this problem."(from the exercise)
hmmm, as in the exercise stated, dyadic ⊂ (partition) is to be used.
So the real challenge is to generate the correct vector as left
argument for ⊂, right?
⍝ first try:
∇ z← size chunkmonkey1 a
z←((⍴a)↑(size/⍳⍴a)) ⊂ a
∇
⍝ BUT
⍝ - doesn't work with a scalar as asked
⍝ - ((⍴a)↑(size/⍳⍴a)) seems inefficient, as we make a to big
⍝ vector and cut it down afterwards... Is this a common/fine
⍝ pattern?
⍝ second try:
∇ z← size chunkmonkey2 a
→((0=≢⍴a)∧1=≢a)/skalar ⍝ matches a skalar, but not ''
z←((≢a)↑(size/⍳≢a))⊂a ⍝ ≢ or ⍴ in this case?
→0
skalar:
z←a
∇
⍝ correct, but feels clumsy...
⍝ - ≢ seems more acurately than ⍴ in this case?
⍝ - should be doable without jump?
⍝ - still the inefficient vector
Final thoughts for now:
What I learned/understood with this exercise: / is not only reduce
(operator), but also dyadic functions filter and especially expand
(not all APL-variants?).
Checking for types is not easy. 0=⍴N is a scalar. Howto check for a
string?
br & and many thanks for any hints, Otto
--
Dipl. Ing. (FH) Otto Diesenbacher-Reinmüller
diesenbacher.net
Salzburg, Österreich
- exercise 2019/01,
Otto Diesenbacher-Reinmüller <=