blob: d9919170860f188abbb52c0672956d783ec34d2f (
plain) (
blame)
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
|
using System.Collections.Generic;
using System.Linq;
namespace aoc2019
{
internal sealed class Day01 : Day
{
private readonly IEnumerable<int> masses;
public Day01() : base(1, "The Tyranny of the Rocket Equation")
{
masses = Input.Select(int.Parse);
}
private static int FuelCost(int weight)
{
return weight / 3 - 2;
}
private static int FullCost(int cost)
{
int total = 0, newcost, tmp = cost;
while ((newcost = FuelCost(tmp)) >= 0)
{
total += newcost;
tmp = newcost;
}
return total;
}
protected override string Part1()
{
return $"{masses.Sum(FuelCost)}";
}
protected override string Part2()
{
return $"{masses.Sum(FullCost)}";
}
}
}
|