-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cs
47 lines (38 loc) · 1.05 KB
/
Solution.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
using AdventOfCode.Lib.Solutions;
namespace AdventOfCode.Y2024.Day01;
public sealed class Solution : LineInputSolution, ISolution
{
private List<int> leftList;
private List<int> rightList;
public Solution(string rawInput) : base(rawInput)
{
leftList = [];
rightList = [];
foreach (string line in lines)
{
var split = line.Split(" ");
leftList.Add(int.Parse(split[0]));
rightList.Add(int.Parse(split[1]));
}
leftList.Sort();
rightList.Sort();
}
public string SolvePartOne()
{
int answer = 0;
for (int i = 0; i < leftList.Count; i++) {
answer += Math.Abs(leftList[i] - rightList[i]);
}
return answer.ToString();
}
public string SolvePartTwo()
{
int answer = 0;
foreach (int number in leftList)
{
var similarityScore = rightList.Count(i => i == number);
answer += number * similarityScore;
}
return answer.ToString();
}
}