-
Notifications
You must be signed in to change notification settings - Fork 0
/
adventOfCode2020day6part1.linq
74 lines (53 loc) · 1.12 KB
/
adventOfCode2020day6part1.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
<Query Kind="Program" />
void Main()
{
var input = ReadMyFile(@"input6.txt");
var groups=ParseInput(input);
var getYesAnswers=groups.Sum(w=>w.YesAnswers).Dump();
}
private List<Group> ParseInput(List<string> inputs){
var list=new List<Group>();
var group= new Group();
foreach (var input in inputs)
{
if(string.IsNullOrEmpty(input)){
list.Add(group);
group=new Group();
}
group.FeedData(input);
}
list.Add(group);
return list;
}
class Group{
public Dictionary<char,int> Answers;
public int YesAnswers;
public Group()
{
Answers=new Dictionary<char,int>();
}
public void FeedData(string input){
foreach (var letter in input.ToCharArray())
{
if(!Answers.ContainsKey(letter)){
Answers.Add(letter,1);
YesAnswers++;
}else{
var value=Answers[letter];
Answers[letter]=value+1;
}
}
}
}
private List<string> ReadMyFile(string uri)
{
var newList = new List<string>();
string line;
System.IO.StreamReader reader = new StreamReader(uri);
while ((line = reader.ReadLine()) != null)
{
newList.Add(line);
}
return newList;
}
// Define other methods and classes here