static void Main(string[] args) { if (args == null || args.Length == 0) { Console.WriteLine("Provide input file!"); return; } var inputFile = Path.GetFullPath(args[0]); //Console.WriteLine($"Processing file {inputFile}"); PizzaDescription pizza; using (var reader = new StreamReader(File.Open(inputFile, FileMode.Open))) { pizza = new PizzaDescription(reader); } var slices = PizzaSlicer.Slice(pizza).ToList(); Console.WriteLine(FormatOutput(slices)); }
public static IEnumerable <Slice> Slice(PizzaDescription pizza) { var possibleSlices = CreateSliceDistribution(pizza.Width, pizza.Height, pizza.ValidSlices); // Greedy approach var greedy = SortedApproach(possibleSlices, pizza.Width, ls => ls.OrderByDescending(s => s.Size).ToList()) .ToList(); var cover = greedy.Sum(slice => slice.Size); if (cover == pizza.Width * pizza.Height) { return(greedy); } // Small slices first var unGreedy = SortedApproach(possibleSlices, pizza.Width, ls => ls.OrderBy(s => s.Size).ToList()) .ToList(); var cover2 = unGreedy.Sum(slice => slice.Size); return(cover > cover2 ? greedy : unGreedy); }