Program.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using D10._1;
  6. using static D10._1.Program;
  7. namespace D10._2
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. if (args.Length < 1) throw new ArgumentException();
  14. if (File.Exists(args[0]) == false) throw new FileNotFoundException();
  15. var bots = new Dictionary<int, Bot>();
  16. var instructions = new Dictionary<Bot, ((int, Bot low), (int, Bot high))>();
  17. var outputs = new int[3];
  18. ParseFile(args, bots, instructions);
  19. while (true)
  20. {
  21. var bot = bots.FirstOrDefault(b => b.Value.IsFull()).Value;
  22. if (bot == null) break;
  23. var lowest = bot.GiveLowest();
  24. var highest = bot.GiveHighest();
  25. var ((lid, low), (hid, high)) = instructions[bot];
  26. if (low != null) low.Take(lowest);
  27. else if (lid < outputs.Length) outputs[lid] = lowest;
  28. if (high != null) high.Take(highest);
  29. else if (hid < outputs.Length) outputs[hid] = highest;
  30. }
  31. Console.WriteLine($"The answer is : { outputs[0] * outputs[1] * outputs[2] }");
  32. }
  33. }
  34. }