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