-
Notifications
You must be signed in to change notification settings - Fork 0
/
adventOfCode2021day1part1.linq
78 lines (63 loc) · 1.1 KB
/
adventOfCode2021day1part1.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
78
<Query Kind="Program" />
void Main()
{
var inputList = new List<int>();
inputList = GetSampleList();
var list=ReadMyFile(@"G:\Git\linq\adventofcode2021\input1.txt");
CountList(list);
}
private void CountList(List<int> input)
{
int? prev = null;
int inc=0;
int dec=0;
foreach (var value in input)
{
if (prev == null)
{
prev = value;
continue;
}
if(value>prev)
inc++;
if(value<prev)
dec++;
prev = value;
}
inc.Dump();
dec.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 List<int> GetSampleList()
{
var newList = new List<int>();
newList.Add(199);
newList.Add(200);
newList.Add(208);
newList.Add(210);
newList.Add(200);
newList.Add(207);
newList.Add(240);
newList.Add(269);
newList.Add(260);
newList.Add(263);
return newList;
}
// Define other methods and classes here