2021-11-10 20:09:57 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-03-12 20:49:17 +00:00
|
|
|
|
using System.Linq;
|
2018-03-12 19:21:16 +00:00
|
|
|
|
|
|
|
|
|
public enum Plant
|
|
|
|
|
{
|
|
|
|
|
Violets,
|
|
|
|
|
Radishes,
|
|
|
|
|
Clover,
|
|
|
|
|
Grass
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class KindergartenGarden
|
2018-03-12 20:49:17 +00:00
|
|
|
|
{
|
2021-11-10 20:09:57 +00:00
|
|
|
|
private readonly List<string> roster;
|
|
|
|
|
private readonly string row1;
|
|
|
|
|
private readonly string row2;
|
2018-03-12 20:49:17 +00:00
|
|
|
|
|
|
|
|
|
private static readonly IDictionary<char, Plant> PlantCodesToPlants = new Dictionary<char, Plant>
|
|
|
|
|
{
|
|
|
|
|
{ 'V', Plant.Violets },
|
|
|
|
|
{ 'R', Plant.Radishes },
|
|
|
|
|
{ 'C', Plant.Clover },
|
|
|
|
|
{ 'G', Plant.Grass }
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-12 19:21:16 +00:00
|
|
|
|
public KindergartenGarden(string diagram)
|
|
|
|
|
{
|
2021-11-10 20:09:57 +00:00
|
|
|
|
var plants = diagram.Split('\n');
|
|
|
|
|
row1 = plants[0]; row2 = plants[1];
|
|
|
|
|
|
2018-03-12 20:49:17 +00:00
|
|
|
|
roster = new List<string>
|
|
|
|
|
{
|
|
|
|
|
"Alice", "Bob", "Charlie", "David",
|
|
|
|
|
"Eve", "Fred", "Ginny", "Harriet",
|
|
|
|
|
"Ileana", "Joseph", "Kincaid", "Larry"
|
|
|
|
|
};
|
2018-03-12 19:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Plant> Plants(string student)
|
|
|
|
|
{
|
2021-11-10 20:09:57 +00:00
|
|
|
|
var i = 2 * roster.IndexOf(student);
|
|
|
|
|
var plants = new List<Plant>();
|
|
|
|
|
plants.AddRange(row1[i..(i + 2)].Select(p => PlantCodesToPlants[p]));
|
|
|
|
|
plants.AddRange(row2[i..(i + 2)].Select(p => PlantCodesToPlants[p]));
|
|
|
|
|
return plants;
|
2018-03-12 19:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|