From 72123d091331c572799611b379772f025fb838e3 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sun, 1 Dec 2019 02:35:17 -0500 Subject: [PATCH] day1 init --- .gitignore | 32 ++++++++++++++++ Day1.cs | 39 +++++++++++++++++++ Program.cs | 15 ++++++++ aoc2019.csproj | 8 ++++ input/day1.in | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 .gitignore create mode 100644 Day1.cs create mode 100644 Program.cs create mode 100644 aoc2019.csproj create mode 100644 input/day1.in diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b5e7d97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +*.swp +*.*~ +project.lock.json +.DS_Store +*.pyc + +# Visual Studio Code +.vscode + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ +msbuild.log +msbuild.err +msbuild.wrn + +# Visual Studio 2015 +.vs/ diff --git a/Day1.cs b/Day1.cs new file mode 100644 index 0000000..570d017 --- /dev/null +++ b/Day1.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace aoc2019 +{ + public class Day1 + { + private static IEnumerable lines = + File.ReadLines("input/day1.in").Select(line => int.Parse(line)); + + private static int FuelCost(int weight) => weight / 3 - 2; + + public static void Part1() + { + Console.WriteLine(lines.Select(num => FuelCost(num)).Sum()); + } + + private static int FullCost(int cost) + { + int total = 0, newcost = 0, tmp = cost; + + while ((newcost = FuelCost(tmp)) >= 0) + { + total += newcost; + tmp = newcost; + } + + return total; + } + + public static void Part2() + { + Console.WriteLine(lines.Select(cost => FullCost(cost)).Sum()); + } + } +} + diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..a88bd9d --- /dev/null +++ b/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.IO; +using System.Linq; + +namespace aoc2019 +{ + class Program + { + static void Main(string[] args) + { + Day1.Part1(); + Day1.Part2(); + } + } +} diff --git a/aoc2019.csproj b/aoc2019.csproj new file mode 100644 index 0000000..7322fb3 --- /dev/null +++ b/aoc2019.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.0 + + + diff --git a/input/day1.in b/input/day1.in new file mode 100644 index 0000000..fb4481d --- /dev/null +++ b/input/day1.in @@ -0,0 +1,100 @@ +94735 +80130 +127915 +145427 +89149 +91232 +100629 +97340 +86278 +87034 +147351 +123045 +91885 +85973 +64130 +113244 +58968 +76296 +127931 +98145 +120731 +98289 +110340 +118285 +60112 +57177 +58791 +59012 +66950 +139387 +145378 +86204 +147082 +84956 +134161 +148664 +74278 +96746 +144525 +81214 +70966 +107050 +134179 +138587 +80236 +139871 +104439 +64643 +145453 +94791 +51690 +94189 +148476 +79956 +81760 +149796 +109544 +57533 +142999 +126419 +115434 +57092 +64244 +109663 +94701 +109265 +145851 +95183 +84433 +53818 +106234 +127380 +149774 +59601 +138851 +54488 +100877 +136952 +61538 +67705 +60299 +130769 +113176 +106723 +133280 +111065 +63688 +139307 +122703 +60162 +89567 +63994 +66608 +126376 +136052 +112255 +98525 +134023 +141479 +98200