-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay1_Pt1.linq
More file actions
36 lines (27 loc) · 806 Bytes
/
Day1_Pt1.linq
File metadata and controls
36 lines (27 loc) · 806 Bytes
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
void Main()
{
string[] input = File.ReadAllText(@"c:\Users\Kaylyn\Desktop\AOC\Day1_A.txt").Trim().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
//string[] testInput = new string[]{"100756"};
double result = CalculateFuelRequirements(input);
Console.WriteLine(result);
}
double CalculateFuelRequirements(string[] input)
{
double result = 0;
foreach (string line in input)
{
double.TryParse(line, out double asNumber);
if (asNumber>0)
{
double resultOfDiv = DivideByThree(asNumber);
double resultOfSubtraction = resultOfDiv - 2;
result += resultOfSubtraction;
}
}
return result;
}
double DivideByThree(double asNumber)
{
return Convert.ToDouble(Math.Floor(asNumber/3));
}
// Define other methods and classes here