commit 06176e2ec255d9b55796f416f4f489967d2a5bbb Author: Giovani Date: Tue Dec 3 18:33:35 2019 -0500 first commit diff --git a/.vs/AdventOfCode2019/v16/.suo b/.vs/AdventOfCode2019/v16/.suo new file mode 100644 index 0000000..bbfc1ed Binary files /dev/null and b/.vs/AdventOfCode2019/v16/.suo differ diff --git a/.vs/AdventOfCode2019/v16/Server/sqlite3/db.lock b/.vs/AdventOfCode2019/v16/Server/sqlite3/db.lock new file mode 100644 index 0000000..e69de29 diff --git a/.vs/AdventOfCode2019/v16/Server/sqlite3/storage.ide b/.vs/AdventOfCode2019/v16/Server/sqlite3/storage.ide new file mode 100644 index 0000000..8222d9b Binary files /dev/null and b/.vs/AdventOfCode2019/v16/Server/sqlite3/storage.ide differ diff --git a/AdventOfCode2019.sln b/AdventOfCode2019.sln new file mode 100644 index 0000000..822aa10 --- /dev/null +++ b/AdventOfCode2019.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29009.5 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProblemOne", "ProblemOne\ProblemOne.csproj", "{58FECE0A-7AC6-47CC-A93A-6D843FC040A0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProblemTwo", "ProblemTwo\ProblemTwo.csproj", "{B2FF7525-4241-41D1-B325-F814DEB7672F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {58FECE0A-7AC6-47CC-A93A-6D843FC040A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {58FECE0A-7AC6-47CC-A93A-6D843FC040A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {58FECE0A-7AC6-47CC-A93A-6D843FC040A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {58FECE0A-7AC6-47CC-A93A-6D843FC040A0}.Release|Any CPU.Build.0 = Release|Any CPU + {B2FF7525-4241-41D1-B325-F814DEB7672F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2FF7525-4241-41D1-B325-F814DEB7672F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2FF7525-4241-41D1-B325-F814DEB7672F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2FF7525-4241-41D1-B325-F814DEB7672F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EBF8B716-389F-47B8-B749-02492D04E273} + EndGlobalSection +EndGlobal diff --git a/ProblemOne/App.config b/ProblemOne/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/ProblemOne/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProblemOne/ProblemOne.csproj b/ProblemOne/ProblemOne.csproj new file mode 100644 index 0000000..565c4ea --- /dev/null +++ b/ProblemOne/ProblemOne.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {58FECE0A-7AC6-47CC-A93A-6D843FC040A0} + Exe + ProblemOne + ProblemOne + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ProblemOne/Program.cs b/ProblemOne/Program.cs new file mode 100644 index 0000000..4ca8731 --- /dev/null +++ b/ProblemOne/Program.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProblemOne +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine(GetTotalFuelRequiredPartOne()); + Console.WriteLine(GetTotalFuelRequiredPartTwo()); + Console.ReadLine(); + } + + static int GetTotalFuelRequiredPartTwo() + { + var totalFuelRequired = 0; + foreach (var massInput in MassInputs) + { + var fuelRequired = massInput; + do + { + fuelRequired = GetFuelRequiredPartOne(fuelRequired); + totalFuelRequired += fuelRequired; + } + while (GetFuelRequiredPartOne(fuelRequired) > 0); + } + + return totalFuelRequired; + } + + static int GetTotalFuelRequiredPartOne() + { + var totalFuelRequired = 0; + foreach (var massInput in MassInputs) + totalFuelRequired += GetFuelRequiredPartOne(massInput); + + return totalFuelRequired; + } + + static int GetFuelRequiredPartOne(int massInput) + { + return (int)(Math.Floor(massInput / 3.0M) - 2.0M); + } + + static List MassInputs = new List() + { + 92349, + 57040, + 64079, + 121555, + 143735, + 64642, + 104858, + 144446, + 88871, + 62338, + 113424, + 59960, + 53999, + 86867, + 67224, + 124130, + 108921, + 130492, + 120361, + 74426, + 70397, + 88106, + 125442, + 74237, + 137818, + 66633, + 71756, + 143276, + 143456, + 135698, + 121124, + 67739, + 112861, + 78572, + 73565, + 111899, + 57543, + 130314, + 121605, + 121426, + 117143, + 129957, + 98042, + 104760, + 144846, + 131238, + 101076, + 53328, + 83592, + 104077, + 101952, + 54137, + 115363, + 60556, + 133086, + 113361, + 117829, + 75003, + 93729, + 140022, + 126219, + 59907, + 140589, + 91812, + 50485, + 56232, + 92858, + 106820, + 123423, + 98553, + 135315, + 95583, + 72278, + 98702, + 55709, + 146773, + 89719, + 134752, + 79562, + 70455, + 88468, + 139824, + 138646, + 117516, + 123267, + 113754, + 120353, + 139145, + 53219, + 63053, + 131434, + 91705, + 53650, + 145234, + 78461, + 119587, + 108976, + 113613, + 121790, + 120366 + }; + } +} diff --git a/ProblemOne/Properties/AssemblyInfo.cs b/ProblemOne/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..31afbb6 --- /dev/null +++ b/ProblemOne/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ProblemOne")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ProblemOne")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("58fece0a-7ac6-47cc-a93a-6d843fc040a0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ProblemOne/bin/Debug/ProblemOne.exe b/ProblemOne/bin/Debug/ProblemOne.exe new file mode 100644 index 0000000..1397645 Binary files /dev/null and b/ProblemOne/bin/Debug/ProblemOne.exe differ diff --git a/ProblemOne/bin/Debug/ProblemOne.exe.config b/ProblemOne/bin/Debug/ProblemOne.exe.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/ProblemOne/bin/Debug/ProblemOne.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProblemOne/bin/Debug/ProblemOne.pdb b/ProblemOne/bin/Debug/ProblemOne.pdb new file mode 100644 index 0000000..70f79df Binary files /dev/null and b/ProblemOne/bin/Debug/ProblemOne.pdb differ diff --git a/ProblemOne/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/ProblemOne/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..16ff0bf Binary files /dev/null and b/ProblemOne/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/ProblemOne/obj/Debug/ProblemOne.csproj.CoreCompileInputs.cache b/ProblemOne/obj/Debug/ProblemOne.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..9b79ae8 --- /dev/null +++ b/ProblemOne/obj/Debug/ProblemOne.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +32b0cee30476cf404bcb931ca8435e90f1b2fd77 diff --git a/ProblemOne/obj/Debug/ProblemOne.csproj.FileListAbsolute.txt b/ProblemOne/obj/Debug/ProblemOne.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..b4c7b1d --- /dev/null +++ b/ProblemOne/obj/Debug/ProblemOne.csproj.FileListAbsolute.txt @@ -0,0 +1,7 @@ +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemOne\ProblemOne\bin\Debug\ProblemOne.exe.config +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemOne\ProblemOne\bin\Debug\ProblemOne.exe +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemOne\ProblemOne\bin\Debug\ProblemOne.pdb +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemOne\ProblemOne\obj\Debug\ProblemOne.csprojAssemblyReference.cache +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemOne\ProblemOne\obj\Debug\ProblemOne.csproj.CoreCompileInputs.cache +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemOne\ProblemOne\obj\Debug\ProblemOne.exe +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemOne\ProblemOne\obj\Debug\ProblemOne.pdb diff --git a/ProblemOne/obj/Debug/ProblemOne.csprojAssemblyReference.cache b/ProblemOne/obj/Debug/ProblemOne.csprojAssemblyReference.cache new file mode 100644 index 0000000..956cbd7 Binary files /dev/null and b/ProblemOne/obj/Debug/ProblemOne.csprojAssemblyReference.cache differ diff --git a/ProblemOne/obj/Debug/ProblemOne.exe b/ProblemOne/obj/Debug/ProblemOne.exe new file mode 100644 index 0000000..1397645 Binary files /dev/null and b/ProblemOne/obj/Debug/ProblemOne.exe differ diff --git a/ProblemOne/obj/Debug/ProblemOne.pdb b/ProblemOne/obj/Debug/ProblemOne.pdb new file mode 100644 index 0000000..70f79df Binary files /dev/null and b/ProblemOne/obj/Debug/ProblemOne.pdb differ diff --git a/ProblemTwo/App.config b/ProblemTwo/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/ProblemTwo/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProblemTwo/ProblemTwo.csproj b/ProblemTwo/ProblemTwo.csproj new file mode 100644 index 0000000..203c760 --- /dev/null +++ b/ProblemTwo/ProblemTwo.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {B2FF7525-4241-41D1-B325-F814DEB7672F} + Exe + ProblemTwo + ProblemTwo + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ProblemTwo/Program.cs b/ProblemTwo/Program.cs new file mode 100644 index 0000000..3504b43 --- /dev/null +++ b/ProblemTwo/Program.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProblemTwo +{ + class Program + { + static void Main(string[] args) + { + /* PART ONE */ + var program = LoadProgramIntoMemory(ProgramStringPartOne); + program = SeedProgram(program, 12, 2); + program = ExecuteProgram(program); + Console.WriteLine(program[0]); + + /* PART TWO */ + for (int noun = 0; noun < 100; noun++) + { + for (int verb = 0; verb < 100; verb++) + { + program = LoadProgramIntoMemory(ProgramStringPartOne); + program = SeedProgram(program, noun, verb); + program = ExecuteProgram(program); + + if (program[0] == 19690720) + Console.WriteLine(100 * noun + verb); + } + } + + Console.ReadLine(); + } + + static int[] LoadProgramIntoMemory(string strProgram) + { + return strProgram.Split(',').Select(x => int.Parse(x)).ToArray(); + } + + static int[] SeedProgram(int[] program, int noun, int verb) + { + program[1] = noun; + program[2] = verb; + + return program; + } + + static int[] ExecuteProgram(int[] program) + { + int parameterCount = 0; + for (int i = 0; i < program.Length; i = i + parameterCount) + { + var operationCode = (Operations)program[i]; + + if (operationCode == Operations.Add) + { + var inputOne = program[i + 1]; + var inputTwo = program[i + 2]; + var result = program[i + 3]; + + program[result] = program[inputOne] + program[inputTwo]; + parameterCount = OperationParameterCount.Add; + } + else if (operationCode == Operations.Multiply) + { + var inputOne = program[i + 1]; + var inputTwo = program[i + 2]; + var result = program[i + 3]; + + program[result] = program[inputOne] * program[inputTwo]; + parameterCount = OperationParameterCount.Multiply; + } + else if (operationCode == Operations.Exit) + { + break; + } + else + throw new Exception("Unsupported Operation"); + } + + return program; + } + + enum Operations + { + Add = 1, + Multiply = 2, + Exit = 99 + } + + static class OperationParameterCount + { + public static int Add => 4; + public static int Multiply => 4; + public static int Exit => 0; + } + + static string ProgramStringPartOne = "1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,6,19,1,5,19,23,1,23,6,27,1,5,27,31,1,31,6,35,1,9,35,39,2,10,39,43,1,43,6,47,2,6,47,51,1,5,51,55,1,55,13,59,1,59,10,63,2,10,63,67,1,9,67,71,2,6,71,75,1,5,75,79,2,79,13,83,1,83,5,87,1,87,9,91,1,5,91,95,1,5,95,99,1,99,13,103,1,10,103,107,1,107,9,111,1,6,111,115,2,115,13,119,1,10,119,123,2,123,6,127,1,5,127,131,1,5,131,135,1,135,6,139,2,139,10,143,2,143,9,147,1,147,6,151,1,151,13,155,2,155,9,159,1,6,159,163,1,5,163,167,1,5,167,171,1,10,171,175,1,13,175,179,1,179,2,183,1,9,183,0,99,2,14,0,0"; + } +} diff --git a/ProblemTwo/Properties/AssemblyInfo.cs b/ProblemTwo/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3c8b44a --- /dev/null +++ b/ProblemTwo/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ProblemTwo")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ProblemTwo")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b2ff7525-4241-41d1-b325-f814deb7672f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ProblemTwo/bin/Debug/ProblemTwo.exe b/ProblemTwo/bin/Debug/ProblemTwo.exe new file mode 100644 index 0000000..5621a8a Binary files /dev/null and b/ProblemTwo/bin/Debug/ProblemTwo.exe differ diff --git a/ProblemTwo/bin/Debug/ProblemTwo.exe.config b/ProblemTwo/bin/Debug/ProblemTwo.exe.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/ProblemTwo/bin/Debug/ProblemTwo.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProblemTwo/bin/Debug/ProblemTwo.pdb b/ProblemTwo/bin/Debug/ProblemTwo.pdb new file mode 100644 index 0000000..7905639 Binary files /dev/null and b/ProblemTwo/bin/Debug/ProblemTwo.pdb differ diff --git a/ProblemTwo/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/ProblemTwo/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..5c6ff51 Binary files /dev/null and b/ProblemTwo/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/ProblemTwo/obj/Debug/ProblemTwo.csproj.CoreCompileInputs.cache b/ProblemTwo/obj/Debug/ProblemTwo.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..9b79ae8 --- /dev/null +++ b/ProblemTwo/obj/Debug/ProblemTwo.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +32b0cee30476cf404bcb931ca8435e90f1b2fd77 diff --git a/ProblemTwo/obj/Debug/ProblemTwo.csproj.FileListAbsolute.txt b/ProblemTwo/obj/Debug/ProblemTwo.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..12128df --- /dev/null +++ b/ProblemTwo/obj/Debug/ProblemTwo.csproj.FileListAbsolute.txt @@ -0,0 +1,7 @@ +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemTwo\bin\Debug\ProblemTwo.exe.config +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemTwo\bin\Debug\ProblemTwo.exe +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemTwo\bin\Debug\ProblemTwo.pdb +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemTwo\obj\Debug\ProblemTwo.csprojAssemblyReference.cache +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemTwo\obj\Debug\ProblemTwo.csproj.CoreCompileInputs.cache +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemTwo\obj\Debug\ProblemTwo.exe +C:\Users\grodriguez\source\repos\AdventOfCode\2019\ProblemTwo\obj\Debug\ProblemTwo.pdb diff --git a/ProblemTwo/obj/Debug/ProblemTwo.csprojAssemblyReference.cache b/ProblemTwo/obj/Debug/ProblemTwo.csprojAssemblyReference.cache new file mode 100644 index 0000000..24df8ab Binary files /dev/null and b/ProblemTwo/obj/Debug/ProblemTwo.csprojAssemblyReference.cache differ diff --git a/ProblemTwo/obj/Debug/ProblemTwo.exe b/ProblemTwo/obj/Debug/ProblemTwo.exe new file mode 100644 index 0000000..5621a8a Binary files /dev/null and b/ProblemTwo/obj/Debug/ProblemTwo.exe differ diff --git a/ProblemTwo/obj/Debug/ProblemTwo.pdb b/ProblemTwo/obj/Debug/ProblemTwo.pdb new file mode 100644 index 0000000..7905639 Binary files /dev/null and b/ProblemTwo/obj/Debug/ProblemTwo.pdb differ