mirror of
https://github.com/ckaczor/Advent2019.git
synced 2026-01-13 17:22:15 -05:00
Initial commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.vs
|
||||
bin
|
||||
obj
|
||||
8
Advent.csproj
Normal file
8
Advent.csproj
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
25
Advent.sln
Normal file
25
Advent.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29519.87
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Advent", "Advent.csproj", "{6D876526-1EA3-484C-B1B2-A6EEFEF7CA23}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6D876526-1EA3-484C-B1B2-A6EEFEF7CA23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6D876526-1EA3-484C-B1B2-A6EEFEF7CA23}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6D876526-1EA3-484C-B1B2-A6EEFEF7CA23}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6D876526-1EA3-484C-B1B2-A6EEFEF7CA23}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {1881BC49-072A-4A7E-9C3B-8172112237CC}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
47
Day1.cs
Normal file
47
Day1.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Advent
|
||||
{
|
||||
public static class Day1
|
||||
{
|
||||
public static void Execute()
|
||||
{
|
||||
var lines = File.ReadAllLines(@"C:\Users\chris\OneDrive\Desktop\input.txt");
|
||||
|
||||
var total = 0.0;
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var mass = double.Parse(line);
|
||||
|
||||
var fuel = CalculateFuel(mass);
|
||||
|
||||
total += fuel;
|
||||
}
|
||||
|
||||
Console.WriteLine(total);
|
||||
}
|
||||
|
||||
private static double CalculateFuel(double mass)
|
||||
{
|
||||
var totalFuel = 0.0;
|
||||
|
||||
var fuel = Math.Floor(mass / 3) - 2;
|
||||
|
||||
totalFuel += fuel;
|
||||
|
||||
while (fuel > 2)
|
||||
{
|
||||
fuel = Math.Floor(fuel / 3) - 2;
|
||||
|
||||
if (fuel < 0)
|
||||
fuel = 0;
|
||||
|
||||
totalFuel += fuel;
|
||||
}
|
||||
|
||||
return totalFuel;
|
||||
}
|
||||
}
|
||||
}
|
||||
61
Day2.cs
Normal file
61
Day2.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Advent
|
||||
{
|
||||
public static class Day2
|
||||
{
|
||||
public static void Execute()
|
||||
{
|
||||
for (var noun = 0; noun <= 99; noun++)
|
||||
for (var verb = 0; verb <= 99; verb++)
|
||||
{
|
||||
var result = Calculate(noun, verb);
|
||||
|
||||
if (result == 19690720)
|
||||
Console.WriteLine(100 * noun + verb);
|
||||
}
|
||||
}
|
||||
|
||||
private static int Calculate(int noun, int verb)
|
||||
{
|
||||
var lines = File.ReadAllLines(@"C:\Users\chris\OneDrive\Desktop\input.txt");
|
||||
|
||||
var codes = lines[0].Split(',').Select(int.Parse).ToArray();
|
||||
|
||||
codes[1] = noun;
|
||||
codes[2] = verb;
|
||||
|
||||
var position = 0;
|
||||
var done = false;
|
||||
|
||||
while (!done)
|
||||
{
|
||||
switch (codes[position])
|
||||
{
|
||||
case 1:
|
||||
codes[codes[position + 3]] = codes[codes[position + 1]] + codes[codes[position + 2]];
|
||||
|
||||
position += 4;
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
codes[codes[position + 3]] = codes[codes[position + 1]] * codes[codes[position + 2]];
|
||||
|
||||
position += 4;
|
||||
|
||||
break;
|
||||
|
||||
case 99:
|
||||
done = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return codes[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Program.cs
Normal file
10
Program.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Advent
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static void Main()
|
||||
{
|
||||
Day2.Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user