-
Notifications
You must be signed in to change notification settings - Fork 0
/
adventOfCode2020day1part1.linq
77 lines (64 loc) · 1.29 KB
/
adventOfCode2020day1part1.linq
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<Query Kind="Program" />
void Main()
{
var inputList = new List<int>();
inputList = GetSampleList();
var res = FindPairWithValue(inputList, 2020);
res.Dump();
var answer = MultiplyValues(res.Item1, res.Item2).Dump();
if (answer != 514579)
{
"Fail".Dump();
}
else
{
"Sample is working".Dump();
}
var res2=FindPairWithValue(ReadMyFile(@"d:\input.txt"),2020);
res2.Dump();
var answer2=MultiplyValues(res2.Item1,res2.Item2);
answer2.Dump();
}
private List<int> ReadMyFile(string uri){
var newList= new List<int>();
string line;
System.IO.StreamReader reader = new StreamReader(uri);
while ((line = reader.ReadLine()) != null)
{
if(int.TryParse(line,out int res)){
newList.Add(res);
}
else{
"was not a int".Dump();
}
}
return newList;
}
private int MultiplyValues(int x, int y)
{
return x * y;
}
private (int, int) FindPairWithValue(List<int> inputs, int value)
{
foreach (var val in inputs)
{
foreach (var testValue in inputs)
{
if (val + testValue == value)
return (val, testValue);
}
}
return (0, 0);
}
private List<int> GetSampleList()
{
var newList = new List<int>();
newList.Add(1721);
newList.Add(979);
newList.Add(366);
newList.Add(299);
newList.Add(675);
newList.Add(1456);
return newList;
}
// Define other methods and classes here