Monster Registry
Learn this problemProblem statement
Task 1
Your task is to create a Monster Registry
Monster Background
- Monsters battle each other.
- Each monster has a unique 3-digit ID number and a name.
- Monsters have types and weaknesses.
- Types determine what other monsters they are strong or weak against.
- For example, a Banub is a fire type monster, and Octopeat has a weakness for fire type monsters. Therefore Banub is strong against Octopeat and Octopeat is weak against Banub.
- A single monster can have more than one type or weakness.
- A monster can evolve into another monster.
- For example, Banub evolves into Banubeleon, who evolves into Banubizard.
- Sometimes, a monster may have a choice of two or more other monsters to evolve into. For example, Ironuin can evolve into Iroume or Irossom.
Detailed Requirements
The program which you will write shall accept a CSV file containing a database of all known monsters, as well as the case-insensitive name of one monster. It will output the other monsters that the given monster is strong and weak against, and an evolution chart for the given monster.
Your program will be provided well-formed input files and valid command line arguments and must print a carefully formatted output.
Submission Guidelines
- The tests will execute the main function without any arguments, parameters will be provided like in command-line execution
- All results must be printed to stdout (not returned from the function)
- Your submission will be run against an automated test suite. This means proper output formatting is essential for correctness.
- To implement your solution, use Python 3.8. You are encouraged to use Python Standard Library modules, but you may not use other 3rd party code.
Database Input File
The first positional argument to your program will be the filename of a comma separated value database file.
- The first row of the file contains categorized column headers.
- Column headers may be sorted in any order.
- Each additional row contains the information entries for a specific monster.
- Required columns:
- "ID"
- "Name"
- "Types"
- "Weaknesses"
- "Evolution"
- Contains the ID(s) of next monster evolution(s)
- If no further evolution exists, this column will be empty.
- Multiple types, weaknesses, or evolution paths will be separated by a single comma and enclosed in double quotes ("").
Monster Registry Output
The second positional argument to your program will be the case-insensitive name of one monster. The program will output the given monster's properties in the following order:
- "ID"
- "Strong against"
- "Weak against"
- "Evolution"
Strengths and Weaknesses
Under the category "Strong against", you must output a list of monsters against which your given monster's type is strong.
- Each of these monsters shall be printed on a new line in order of monster ID.
- If no known monster exist with weaknesses for the given monster's type, print "None".
Under the category "Weak against", you must output a list of monsters against which your given monster's type is weak.
- Each of these monsters shall be printed on a new line in order of monster ID.
- If no known monster exist which are a type that the given monster is weak against, print "None".
Evolution Chart
The final output category, "Evolution", shall contain an evolution chart for the monster.
- Start with the current monster
- If no further evolution is possible, end.
- Continue until the final form
- Each form shall be separated by a single space, a single >, and another single space " > ".
- Multiple evolution paths shall be printed on new lines.
- Evolution paths shall be printed in depth-first-search order, sorted by monster ID.
Output Formatting
Your program must meet the following requirements for output format.
- Each category of information shall be followed by a single colon.
- The information shall be printed on the following line, indented by 4 spaces.
- Print exactly one new line at the end of the output.
Examples Inputs and Outputs
These examples are separated by a blank new line for clarity. This new line must not be included in the expected inputs or outputs.
Example Input File
$ cat database.csv
ID,Name,Types,Weaknesses,Evolution
004,Banub,Fire,"Ground,Rock,Water",005
005,Banubeleon,Fire,"Ground,Rock,Water",006
006,Banubizard,"Fire,Flying","Rock,Electric,Water",
043,Octopeat,"Grass,Poison","Fire,Flying,Ice,Psychic",044
044,Octoplat,"Grass,Poison","Fire,Flying,Ice,Psychic","045,182"
045,Octonyte,"Grass,Poison","Fire,Flying,Ice,Psychic",
182,Bibyss,Grass,"Bug,Fire,Flying,Ice,Poison",Example Program Output
Example 1
$ python solution database.csv Banubeleon
ID:
005
Strong against:
Octopeat
Octoplat
Octonyte
Bibyss
Weak against:
None
Evolution:
Banubeleon > BanubizardExample 2
$ python solution database.csv Octopeat
ID:
043
Strong against:
Bibyss
Weak against:
Banub
Banubeleon
Banubizard
Evolution:
Octopeat > Octoplat > Octonyte
Octopeat > Octoplat > BibyssPractice Contract
The original task wording above is preserved. In the judged callable form, databaseRows contains the header followed by every CSV data row, monsterName is the case-insensitive query, and the function returns the exact text that the original program prints.
For this exercise, assume monster names are unique when compared case-insensitively, the evolution graph is acyclic, and a monster appears at most once in each strong or weak list even when multiple types match. All lists of monsters are ordered by numeric monster ID. The returned string must include exactly one trailing newline.
Function
buildMonsterRegistry(databaseRows: String[], monsterName: String) → StringExamples
Example 1
databaseRows = ["ID,Name,Types,Weaknesses,Evolution","004,Banub,Fire,\"Ground,Rock,Water\",005","005,Banubeleon,Fire,\"Ground,Rock,Water\",006","006,Banubizard,\"Fire,Flying\",\"Rock,Electric,Water\",","043,Octopeat,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",044","044,Octoplat,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",\"045,182\"","045,Octonyte,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",","182,Bibyss,Grass,\"Bug,Fire,Flying,Ice,Poison\","]monsterName = "Banubeleon"return = "ID:\n 005\nStrong against:\n Octopeat\n Octoplat\n Octonyte\n Bibyss\nWeak against:\n None\nEvolution:\n Banubeleon > Banubizard\n"Banubeleon is a Fire type, so it is strong against the four monsters whose weaknesses include Fire. No listed monster has a type that matches Banubeleon's weaknesses. Its only evolution path ends at Banubizard.
Example 2
databaseRows = ["ID,Name,Types,Weaknesses,Evolution","004,Banub,Fire,\"Ground,Rock,Water\",005","005,Banubeleon,Fire,\"Ground,Rock,Water\",006","006,Banubizard,\"Fire,Flying\",\"Rock,Electric,Water\",","043,Octopeat,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",044","044,Octoplat,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",\"045,182\"","045,Octonyte,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",","182,Bibyss,Grass,\"Bug,Fire,Flying,Ice,Poison\","]monsterName = "Octopeat"return = "ID:\n 043\nStrong against:\n Bibyss\nWeak against:\n Banub\n Banubeleon\n Banubizard\nEvolution:\n Octopeat > Octoplat > Octonyte\n Octopeat > Octoplat > Bibyss\n"Octopeat's Grass type is strong against Bibyss, whose weaknesses include Grass. Its Fire weakness makes it weak against the three Fire-type monsters. The evolution graph branches at Octoplat, and DFS visits ID 045 before ID 182.
Constraints
2 ≤ databaseRows.length ≤ 10,001- The first row contains each required header exactly once, in any order.
- Every remaining row is well-formed CSV and contains a unique 3-digit ID and a non-empty name.
- Names are unique under case-insensitive comparison.
- Types, weaknesses, and evolution IDs are comma-separated inside a CSV field and may be empty.
- Every evolution ID names a monster in the database, and the evolution graph is acyclic.
- The total input size is at most
1,000,000characters.