bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

exercise 2019/02


From: Otto Diesenbacher-Reinmüller
Subject: exercise 2019/02
Date: Tue, 14 Apr 2020 17:40:26 +0200
User-agent: mu4e 1.0; emacs 28.0.50

Hi APLers,

let's start with the second challenge:

2 making the grade
(https://www.dyalog.com/uploads/files/student_competition/2019_problems_phase1.pdf)

"Write a function that, given an array of integer testscores in the
inclusive range 0–100, returns anidentically-shaped array of the
corresponding lettergrades according to the table to the left.Hint:
You may want to investigate the intervalindex function ⍸."(from the exercise)
┌────────┐
│ 0  64 F│
│65  69 D│
│70  79 C│
│80  89 B│
│90 100 A│
└────────┘

⍝ so - ⍸ is not applicable as Dyalog-only, let's try without it.

⍝ create the score card: 

table ← 1 3 ⍴ 0 64 'F'
table ← table ⍪ 65 69 'D'
table ← table ⍪ 70 79 'C'
table ← table ⍪ 80 89 'B'
table ← table ⍪ 90 100 'A'

∇z←getGrade iscore
  z←({(iscore≥⍺)∧(iscore≤⍵)}/table[;1 2])/table[;3]
∇

∇grades←findGrade scores
  grades ← getGrade ¨ scores   ⍝ apply getGrade to EACH score
∇

      findGrade 2 2 ⍴ 50 72 91 88
 F C 
 A B 

for sure, it would be better, to live without the *external* getGrade
function. But trying to incorporate the getGrade as a lambda, I
couldn't solve the nested "⍵"s and nested lambdas.

Any hint? 

br & many thanks - Otto

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]