Beispiel #1
0
 static Solver()
 {
     // Get all classes that have the SolutionClass attribute.
     // These hold the solutions for each day.
     types = Assembly.Load("Solutions").GetTypes()
             .Where(x => SolutionClassAttribute.GetAttribute(x) != null)
             .ToDictionary(x => SolutionClassAttribute.GetAttribute(x).Day);
 }
Beispiel #2
0
        /// <summary>
        /// Run a specific solution for a given day.
        /// </summary>
        /// <param name="day">The day.</param>
        /// <param name="type">The solution type.</param>
        /// <param name="part">The solution part.</param>
        public static void Run(int day, SolutionType type, int part)
        {
            var solutionType = types[day];

            var classAttribute = SolutionClassAttribute.GetAttribute(solutionType);

            var instance = Activator.CreateInstance(solutionType);

            var methods = solutionType.GetMethods()
                          .Where(m => SolutionMethodAttribute.GetAttribute(m) != null)
                          .ToDictionary(x => SolutionMethodAttribute.GetAttribute(x).Part);

            if (methods.ContainsKey(part))
            {
                methods[part].Invoke(instance, null);
            }
        }