bug-apl
[Top][All Lists]

## exercise 2019/03

 From: Otto Diesenbacher-Reinmüller Subject: exercise 2019/03 Date: Fri, 17 Apr 2020 17:29:58 +0200 User-agent: mu4e 1.0; emacs 28.0.50

Hi APLers,

regarding 2019/02. I learned a lot, and tried to incooperate in my
solution for 2019/03, having had a deeper look in ∘.X, outer product!

"The school's administrative department wants to publish some simple
statistics. Given anon-empty character vector of single-letter grades,
produce a 3-column, 5-row,alphabetically-sorted matrix of each grade,
the number of occurrences of that grade, andthe percentage (rounded to 1
decimal position) of the total number of occurrences ofthat grade. The
table should have a row for each grade even if there are no
occurrencesof a grade. Note: due to rounding the last column might not
total 100%.  Hint: The key operator ⌸ could be useful for this problem."
(from the exercise)

table←allgr,+/allgr ∘.= ,grades     ⍝ outer product =, and sum 1s up
table←table,+/table[;2]             ⍝ 3rd column with sum
table[;3]←10÷⍨⌊0.5+1000×table[;2]÷table[;3] ⍝ calculate col2÷col3 and round
⍝ for sure, rounding could also be done
⍝ with ⍕!
∇

br & many thanks for any hint! - Otto

--
Dipl. Ing. (FH) Otto Diesenbacher-Reinmüller
diesenbacher.net
Salzburg, Österreich