01020304050607080910111213141516171819202122232425

Advent of Code

2015/2

I Was Told There Would Be No Math

in C#

by encse

The elves are running low on wrapping paper, and so they need to submit an order for more. They have a list of the dimensions (length l, width w, and height h) of each present, and only want to order exactly as much as they need.

Fortunately, every present is a box (a perfect right rectangular prism), which makes calculating the required wrapping paper for each gift a little easier: find the surface area of the box, which is 2*l*w + 2*w*h + 2*h*l. The elves also need a little extra paper for each present: the area of the smallest side.

Read the full puzzle.

using System.Collections.Generic;
using System.Linq;

namespace AdventOfCode.Y2015.Day02;

[ProblemName("I Was Told There Would Be No Math")]
class Solution : Solver {

    public object PartOne(string input) => (
            from nums in Parse(input) 
            select 2 * (nums[0] * nums[1] + nums[1] * nums[2] + nums[0] * nums[2]) + nums[0] * nums[1]
        ).Sum();

    public object PartTwo(string input) => (
            from nums in Parse(input) 
            select nums[0] * nums[1] * nums[2] + 2 * (nums[0] + nums[1])
        ).Sum();

    IEnumerable<int[]> Parse(string input) {
        return (from line in input.Split('\n')
                let parts = line.Split('x')
                let nums = parts.Select(int.Parse).OrderBy(x => x).ToArray()
                select nums);
    }
}

Please ☆ my repo if you like it!

© 2025 Advent of Code is a registered trademark in the US Images provided by Bing image creator