-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdayOne.cs
More file actions
66 lines (63 loc) · 2.03 KB
/
Copy pathdayOne.cs
File metadata and controls
66 lines (63 loc) · 2.03 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace AdventOfCode
{
static class dayOne
{
public static int Ex1()
{
string freq = string.Empty;
int result = 0;
List<int> partial = new List<int>();
partial.Add(result);
using (StreamReader file = new StreamReader(@"C:\Users\ale\Documents\Visual Studio 2015\Projects\AdventOfCode\day1e1.txt"))
{
while ((freq = file.ReadLine()) != null)
{
partial.Add(result += Convert.ToInt32(freq));
}
}
return partial.Last<int>();
}
public static int? Ex2()
{
int? found = null;
string freq = string.Empty;
int result = 0;
List<int> partial = new List<int>();
partial.Add(result);
List<int> numsToSum = new List<int>();
using (StreamReader file = new StreamReader(@"C:\Users\ale\Documents\Visual Studio 2015\Projects\AdventOfCode\day1e1.txt"))
{
while ((freq = file.ReadLine()) != null)
{
numsToSum.Add(Convert.ToInt32(freq));
//partial.Add(result += Convert.ToInt32(freq));
}
}
while (found == null)
{
foreach (var n in numsToSum)
{
var r = partial.Last<int>() + n;
////partial.Add(r);
int lio = partial.LastIndexOf(r);
if (partial.Contains(r))
{
found = r;
break;
}
else
{
partial.Add(r);
}
}
}
return found;
}
}
}