day1 init
This commit is contained in:
commit
72123d0913
|
@ -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/
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -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
|
Loading…
Reference in New Issue