Last active
May 5, 2018 11:54
-
-
Save libeako/b009906bc94d3beb33172a3ee66f67e1 to your computer and use it in GitHub Desktop.
a job interview task solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- preliminaries | |
type Score = Integer | |
type SkillSet = Array Score | |
newtype Salary = WrapSalary { unwrapSalary :: Integer {-^ HUF / month -} } | |
deriving (Ord) | |
data Candidate = Candidate | |
{ | |
name :: String, | |
skill_set :: SkillSet, | |
salary_demand :: Salary | |
} | |
-- the selection algorithm | |
-- | computes the candidates best according to the given evluation function | |
select_best :: Ord score => (e -> score) -> List e -> List e | |
select_best evaluation = | |
let | |
best_score = map second >>> min | |
select_with_score_at_least s = filter (second >>> (>= s)) >>> map first | |
in | |
map (id &&& evaluation) >>> | |
(select_with_score_at_least &&& best_score) >>> | |
(=<<) >>> concat | |
select_candidate :: List Candidate -> Maybe Candidate | |
select_candidate = select_best (skill_set >>> fold) >>> minBy salary_demand |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment