public static long CalculateMaximumFuel() { long ore = 1000000000000; var fuel = Chemical.Get("FUEL"); var store = Chemical.Chemicals.Select(kvp => kvp.Value).ToDictionary(c => c, c => 0L); Stopwatch sw = Stopwatch.StartNew(); long count = 0; while (ore > 0) { int tryProduce = 1; //if (ore > 5000000000000) tryProduce = 1000; //if (ore > 2000000000000) tryProduce = 100; //if (ore > 1000000000000) tryProduce = 10; var required = CountRequiredOre(fuel, tryProduce, store); if (ore < required) { break; } ore -= required; count++; if (sw.Elapsed > TimeSpan.FromSeconds(1)) { long spent = 1000000000000 - ore; double percent = (double)spent / 1000000000000; Console.WriteLine($"{percent * 100}%"); sw.Restart(); } } return(count); }
public ReactionComponent(string definition) { var pair = definition.Trim().Split(" "); Count = int.Parse(pair[0]); Chemical = Chemical.Get(pair[1]); }
public static long CountOreForOneFuel() { var fuel = Chemical.Get("FUEL"); var store = Chemical.Chemicals.Select(kvp => kvp.Value).ToDictionary(c => c, c => 0L); var amount = CountRequiredOre(fuel, 1, store); return(amount); }