-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay01.cs
54 lines (47 loc) · 1.3 KB
/
Day01.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace AdventOfCode2022;
internal class Day01
{
private readonly List<List<int>> _data;
public Day01(string input)
{
_data = input
.Split(Environment.NewLine + Environment.NewLine, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList())
.ToList();
}
public int PartOne()
{
return _data
.Select(x => x.Sum())
.Max();
}
public int PartTwo()
{
return _data
.Select(x => x.Sum())
.OrderByDescending(x => x)
.Take(3)
.Sum();
}
}
public class Day01Test
{
private const string InputFile = "Day01.Input.txt";
private const string ExampleFile = "Day01.Example.txt";
[Theory]
[FileData(ExampleFile, 24000)]
[FileData(InputFile, 69528)]
public void TestPartOne(string input, int expected)
{
var solution = new Day01(input);
Assert.Equal(expected, solution.PartOne());
}
[Theory]
[FileData(ExampleFile, 45000)]
[FileData(InputFile, 206152)]
public void TestPartTwo(string input, int expected)
{
var solution = new Day01(input);
Assert.Equal(expected, solution.PartTwo());
}
}