mirror of
https://github.com/ckaczor/Advent2019.git
synced 2026-01-13 17:22:15 -05:00
Some reorg so I can have the original inputs
This commit is contained in:
47
Day1/Day1.cs
Normal file
47
Day1/Day1.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Advent
|
||||
{
|
||||
public static class Day1
|
||||
{
|
||||
public static void Execute()
|
||||
{
|
||||
var lines = File.ReadAllLines(@".\Day1\input.txt");
|
||||
|
||||
var total = 0.0;
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var mass = double.Parse(line);
|
||||
|
||||
var fuel = CalculateFuel(mass);
|
||||
|
||||
total += fuel;
|
||||
}
|
||||
|
||||
Console.WriteLine(total);
|
||||
}
|
||||
|
||||
private static double CalculateFuel(double mass)
|
||||
{
|
||||
var totalFuel = 0.0;
|
||||
|
||||
var fuel = Math.Floor(mass / 3) - 2;
|
||||
|
||||
totalFuel += fuel;
|
||||
|
||||
while (fuel > 2)
|
||||
{
|
||||
fuel = Math.Floor(fuel / 3) - 2;
|
||||
|
||||
if (fuel < 0)
|
||||
fuel = 0;
|
||||
|
||||
totalFuel += fuel;
|
||||
}
|
||||
|
||||
return totalFuel;
|
||||
}
|
||||
}
|
||||
}
|
||||
100
Day1/input.txt
Normal file
100
Day1/input.txt
Normal file
@@ -0,0 +1,100 @@
|
||||
120588
|
||||
137636
|
||||
114877
|
||||
118328
|
||||
97394
|
||||
58497
|
||||
139343
|
||||
80307
|
||||
125063
|
||||
70956
|
||||
119676
|
||||
76115
|
||||
91916
|
||||
64618
|
||||
82881
|
||||
57000
|
||||
141785
|
||||
73460
|
||||
68992
|
||||
125701
|
||||
97839
|
||||
137800
|
||||
111051
|
||||
104591
|
||||
114396
|
||||
60210
|
||||
80238
|
||||
112009
|
||||
70265
|
||||
140582
|
||||
58765
|
||||
96848
|
||||
130438
|
||||
55615
|
||||
53903
|
||||
109361
|
||||
129512
|
||||
75888
|
||||
93231
|
||||
54697
|
||||
125320
|
||||
53614
|
||||
87173
|
||||
71762
|
||||
147739
|
||||
131840
|
||||
123979
|
||||
54434
|
||||
121517
|
||||
113518
|
||||
83544
|
||||
124924
|
||||
76608
|
||||
130483
|
||||
149285
|
||||
134147
|
||||
111589
|
||||
88174
|
||||
136392
|
||||
94448
|
||||
139244
|
||||
54064
|
||||
85110
|
||||
102985
|
||||
95646
|
||||
54649
|
||||
129755
|
||||
135795
|
||||
119653
|
||||
147633
|
||||
108386
|
||||
143180
|
||||
126587
|
||||
119273
|
||||
130579
|
||||
56006
|
||||
83232
|
||||
99948
|
||||
147711
|
||||
83092
|
||||
99706
|
||||
98697
|
||||
143231
|
||||
94526
|
||||
53102
|
||||
86002
|
||||
71413
|
||||
111054
|
||||
147220
|
||||
136504
|
||||
59308
|
||||
61123
|
||||
148771
|
||||
113986
|
||||
55483
|
||||
94426
|
||||
62791
|
||||
100959
|
||||
63604
|
||||
112511
|
||||
Reference in New Issue
Block a user