about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.gitignore32
-rw-r--r--Day1.cs39
-rw-r--r--Program.cs15
-rw-r--r--aoc2019.csproj8
-rw-r--r--input/day1.in100
5 files changed, 194 insertions, 0 deletions
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<int> 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 @@
+<Project Sdk="Microsoft.NET.Sdk">

+

+  <PropertyGroup>

+    <OutputType>Exe</OutputType>

+    <TargetFramework>netcoreapp3.0</TargetFramework>

+  </PropertyGroup>

+

+</Project>

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