private static int CalculateWrappingAreaForPackage(Box box) { var areas = new List<int>(4) {GetArea(box.Length, box.Width), GetArea(box.Width, box.Height), GetArea(box.Height, box.Length)}; var smallest = areas.OrderBy(i => i).First(); areas.Add(smallest>>1); if (areas.Count != 4) throw new Exception("Not the correct number of elements in list"); return areas.Sum(i => i); }
private static int CalculateLengthOfRibbonToWrapTheBox(Box box) { var orderedValues = new List<int> {box.Height, box.Length, box.Width}.OrderBy(i => i); const int limit = 2; var result = 0; for (var i = 0; i < limit; i++) { result += orderedValues.ElementAt(i) + orderedValues.ElementAt(i); } var bow = orderedValues.Aggregate(1, (x, y) => x*y); return result + bow; }
public static List<Box> Puzzle1Boxes() { var rows = Puzzle1InputData.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries); var result = new ConcurrentBag<Box>(); Parallel.ForEach(rows, (row) => { var iRow = row.Trim(); var split = iRow.Split('x'); var box = new Box(int.Parse(split[0]), int.Parse(split[1]), int.Parse(split[2])); result.Add(box); }); return result.ToList(); }