using System; using System.Collections.Generic; using System.IO; using System.Linq; using D10._1; using static D10._1.Program; namespace D10._2 { class Program { static void Main(string[] args) { if (args.Length < 1) throw new ArgumentException(); if (File.Exists(args[0]) == false) throw new FileNotFoundException(); var bots = new Dictionary(); var instructions = new Dictionary(); var outputs = new int[3]; ParseFile(args, bots, instructions); while (true) { var bot = bots.FirstOrDefault(b => b.Value.IsFull()).Value; if (bot == null) break; var lowest = bot.GiveLowest(); var highest = bot.GiveHighest(); var ((lid, low), (hid, high)) = instructions[bot]; if (low != null) low.Take(lowest); else if (lid < outputs.Length) outputs[lid] = lowest; if (high != null) high.Take(highest); else if (hid < outputs.Length) outputs[hid] = highest; } Console.WriteLine($"The answer is : { outputs[0] * outputs[1] * outputs[2] }"); } } }