|
From: | Hans-Peter Sorge |
Subject: | Re: exercise 2019/03 |
Date: | Sat, 18 Apr 2020 15:21:56 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 |
Hi, I made some 'adjustments', specifically join the table columns from intermediate results use disclose to create the 3rd table column. Also keeps the data 'flat' until 'structure' is required. ∇gradeDistri [⎕]∇ ∇ [0] table←gradeDistri_2 grades;allgr [1] allgr←'ABCDF' ⍝ all available grades[2] gs ← +/ allgr ∘.= ,grades ⍝ outer product =, and sum 1s up
[3] fract←gs÷(0=+/gs)++/gs ⍝ fraction, no div/0[4] table ← allgr,gs,⊃(⊂'550.0')⍕¨100×fract ⍝ grades, counts, format per cent
[5] ⍝ rounding with ⍕ + one decimal position in all cases ∇ ⍝ Test gradeDistri ¨ 'AAAAABBBBCCCDDF' 'ABCDEFG' 'E' 'A' '' A 5 33.3 A 1 20.0 A 0 0.0 A 1 100.0 A 0 0.0 B 4 26.7 B 1 20.0 B 0 0.0 B 0 0.0 B 0 0.0 C 3 20.0 C 1 20.0 C 0 0.0 C 0 0.0 C 0 0.0 D 2 13.3 D 1 20.0 D 0 0.0 D 0 0.0 D 0 0.0 F 1 6.7 F 1 20.0 F 0 0.0 F 0 0.0 F 0 0.0 Regards Hans-Peter Am 17.04.20 um 22:29 schrieb Hans-Peter Sorge:
Hi, this case should be all zeros: gradeDistri 'G' A 0 100 B 0 100 C 0 100 D 0 100 F 0 100 looks ok: gradeDistri 'AG' A 1 100 B 0 0 C 0 0 D 0 0 F 0 0 Regards Hans-Peter Am 17.04.20 um 17:29 schrieb Otto Diesenbacher-Reinmüller:Hi APLers, first, many thanks to Mohammad, Kacper and Hans-Peter for your hints 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! 3: Grade Distribution(https://www.dyalog.com/uploads/files/student_competition/2019_problems_phase1.pdf)"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←gradeDistri grades;allgr allgr←⍪'ABCDF' ⍝ all available grades table←allgr,+/allgr ∘.= ,grades ⍝ outer product =, and sum 1s up table←table,+/table[;2] ⍝ 3rd column with sumtable[;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
[Prev in Thread] | Current Thread | [Next in Thread] |