Skip to content

Instantly share code, notes, and snippets.

@libeako
Last active May 5, 2018 11:54
Show Gist options
  • Save libeako/b009906bc94d3beb33172a3ee66f67e1 to your computer and use it in GitHub Desktop.
Save libeako/b009906bc94d3beb33172a3ee66f67e1 to your computer and use it in GitHub Desktop.
a job interview task solution
-- 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