-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathYear2015Day02.cs
38 lines (35 loc) · 910 Bytes
/
Year2015Day02.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Linq;
using AdventOfCode.Common;
using JetBrains.Annotations;
namespace AdventOfCode.Solutions._2015._2;
[UsedImplicitly]
public class Year2015Day02 : ISolution
{
public object Part1(IEnumerable<string> input)
{
var result = 0;
foreach (var dimension in input)
{
var dims = dimension.Split('x').Select(int.Parse).ToList();
int l = dims[0],
w = dims[1],
h = dims[2];
var smallestSide = Math.Min(Math.Min(l * w, w * h), h * l);
result += smallestSide + 2 * l * w + 2 * w * h + 2 * h * l;
}
return result.ToString();
}
public object Part2(IEnumerable<string> input)
{
var result = 0;
foreach (var dimension in input)
{
var dims = dimension.Split('x').Select(int.Parse).ToList();
dims.Sort();
result += dims[0] * 2 + dims[1] * 2 + dims.Aggregate((i, w) => i * w);
}
return result.ToString();
}
}