-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (43 loc) · 1.49 KB
/
Program.cs
File metadata and controls
49 lines (43 loc) · 1.49 KB
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
using static System.Formats.Asn1.AsnWriter;
namespace day1
{
internal class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader("day1.txt");
List<int> left = new List<int>();
List<int> right = new List<int>();
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
string[] pairs = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
left.Add(int.Parse(pairs[0]));
right.Add(int.Parse(pairs[1]));
}
sr.Close();
//first task:
left.Sort(); right.Sort();
int finalNum = 0;
for (int i = 0; i < left.Count; i++)
{
int distance = Math.Abs(left[i] - right[i]);
finalNum += distance;
}
Console.WriteLine($"Distance between lists: {finalNum}");
//second task:
int similarityScore = 0;
int count = 0;
for (int i = 0; i < left.Count; i++)
{
for (int j = 0; j < right.Count; j++)
{
if (left[i] == right[j]) { count++; }
}
similarityScore += count * left[i];
count = 0;
}
Console.WriteLine($"Similarity score: {similarityScore}");
}
}
}