Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1.     class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             var inputs = File.ReadAllLines("input.txt").Select(line => int.Parse(line));
  6.             Console.WriteLine($"Part 1: Total fuel required is {inputs.Sum(FuelRequired)}");
  7.             Console.WriteLine($"Part 2: Total fuel required is {inputs.Sum(TotalFuelRequired)}");
  8.         }
  9.  
  10.         static int TotalFuelRequired(int mass)
  11.         {
  12.             var fuel = FuelRequired(mass);
  13.             return fuel == 0 ? 0 : fuel + TotalFuelRequired(fuel);
  14.         }
  15.  
  16.         static int FuelRequired(int mass) => Math.Max((mass / 3) - 2, 0);
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement