mirror of
https://github.com/ckaczor/Advent2019.git
synced 2026-02-16 10:48:30 -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user