My work has recently changed the employee tracking system to one that happens to include a fun game to learn your coworker's faces:
Just a small problem: all the pictures include that person's trigram, which is derived from their name.
It then becomes quite easy to find the only name in the list that could have generated that trigram and click it, yeilding many points (yes, there is a company-wide scoreboard).
A trigram is 3 letters. The first letter is always the the first letter of the first name.
Depending on gender (how very archaic of us), the rest is:
- if female: the second letter is the second letter of the first name, and the third is the first letter of the last name.
- if male: the second and third letters are the first and second letters of the last name, respectively.
Some examples might be clearer:
John Doe, M -> JDO
Jane Doe, F -> JAD
Task:
Given a trigram and a gender, choose the name of that person from a list.
IO:
Input: a 3-character string, a gender marker, and a collection of strings representing the list to choose from. Format flexible.
Ouput: Something that represents the correct choice. It could be the full string, or the index of that string or any reasonable other thing. Format flexible.
The gender is binary for the purposes of this challenge.
The trigram will not contain whitespace.
There will always be a correct name in the list, and it will always be unambiguous.
You are not required to parse whether or not a name in the list is "male" or "female". If the trigram parses to that name, it is correct regardless of if it is the "correct" gender.
The list may contain an arbitrary number of names.
Names are always composed of 1 first name and 1 last name. you may take them in whatever way you see fit, including as an array, space separated, a tuple, two lists, etc.
You may take input strings capitalized how you see fit, but the capitalization must be consistent across all strings.
test cases:
["JDO", M, ["John Doe", "John Dae"]] -> 0 (only first matches)
["JDO", M, ["John Doe", "Jdane Orwell"]] -> 0 (only first is correct, because the second only works if gender is F)
["JDO", F, ["John Doe", "Jdane Orwell"]] -> 1 (opposite of above)
["JOD", F, ["John Doe", "Jane Doe"]] -> 0 (even though john is typically a "male" name, it's still the correct answer)
["JAD", F,
["John Doe", "Jdane Orwell", "John Dae", "Jane Doe", "Jane Adsten"] -> 3
["JAD", M,
["John Doe", "Jdane Orwell", "John Dae", "Jane Doe", "Jane Adsten"] -> 4