Adding Day 2 Input and Solution

This commit is contained in:
Brandon Scott 2018-12-08 22:20:32 -06:00
parent 83508ce6a5
commit 0136463fbe
3 changed files with 327 additions and 0 deletions

View File

@ -9,6 +9,9 @@
<None Update="Input\Day1Input.txt"> <None Update="Input\Day1Input.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="Input\Day2Input.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

250
AoC2018/Input/Day2Input.txt Normal file
View File

@ -0,0 +1,250 @@
ybruvapdgixszyckwtfqjonsie
mbruvapxghslyyckwtfqjonsie
mbruvapdghslzyckwtkujonsie
rwruvapdghxlzyckwtfqjcnsie
obruvapdgtxlzyckwtfqionsie
lbruvapdghxqzyckwtfqjfnsie
mbrunapdghxlzyccatfqjonsie
mbruvapdghxlzyokltfqjdnsie
ybruvapdghxlzmckwtfqjmnsie
mbruwaadghxdzyckwtfqjonsie
muruvapdghxlzyckvtfqjonsim
mbruvapdghxlkyckwtxqjonjie
mbruvaqdghxlzyckwtfqjrnnie
mwruvapdghdlzyckttfqjonsie
mbruvapdgtelzyckwxfqjonsie
mbruvapdohxlzvckwtfqjonhie
mbrugapdgbxlzyckwtfqjynsie
mbruvapdghxlzyckwtlqjonjiu
mbruvapwghxlzyckwafqjonbie
wbruvapdghxlhyckwtfqjonsii
mbruvapdghxlzyckwtcqnonsiq
mbyuvapighxlzybkwtfqjonsie
mbrrvapdghxvzyckwtfqjonsio
mhruvapdghrlzyckwtfzjonsie
mtruvapvghxlzyckwtfnjonsie
mmrlhapdghxlzyckwtfqjonsie
mbruvapdgpxlzyjkwtfqjovsie
mbrucapdghxlzymkwtzqjonsie
mbeuvafdghxlzyckwtfqjonwie
mbruvapcghxlayckwtfqjonsii
mbruvabdghxlzyckwtfqyansie
mbruvjpdghxlzyckwtfqgfnsie
lbruvapdghxlzyckwtfqjonriv
mbrupapdghxlzycjwtfqronsie
mbpuvapdthxlzymkwtfqjonsie
mbiuvapdgixlzyckwxfqjonsie
mbruvapdghxyzyckwtfcjonsbe
mbrurapkghxlzyckwtfqjonzie
mbrufapdrhxlzyciwtfqjonsie
mbruvapdghxlzbckwtfqjoisae
ubruhapdghxlzuckwtfqjonsie
mbruvapdjhulzyckwtfqjonshe
mbruwapdgyxlzyckntfqjonsie
mwruvapdghplzyckwtfqjonsme
mbruvapjghtlzyckwtfqgonsie
pbruvapdghhlzyckwtfrjonsie
mbruvgpdihxqzyckwtfqjonsie
mbruvahdohxlzyckwtfijonsie
ibuuvapdghxlzyckwtfqjofsie
mbruvandghxlzyckwtfqjrnxie
mbrjvlpdghxlzyckwgfqjonsie
mbruvapogfxlzyckotfqjonsie
mbruvrpdghxlzyckutfejonsie
mbruvbpdghxlzyhkwtfqjonsip
mbruvapdghxlzyckmnfqjensie
mbruvapdghvlzyckwtfqjowsix
mbruvakdgholzwckwtfqjonsie
mbruvapdghxlzackwtfqconsae
mbruvapdghxlzyqvwtfqjlnsie
mprrvapdgfxlzyckwtfqjonsie
mbrunacdghxlhyckwtfqjonsie
obruvapdgsxlzyckwtfqjonvie
murcvapdghslzyckwtfqjonsie
mbruvapdghxlzyzkwmftjonsie
mbrwvapdgtvlzyckwtfqjonsie
mbxuvapdghxlzqcnwtfqjonsie
mbruvaddghxboyckwtfqjonsie
mhruvwndghxlzyckwtfqjonsie
mbrdvapdghxlzyckwmpqjonsie
mbruvapdgyxlzyckizfqjonsie
mbruvapdghxlzlckwtfqeowsie
mbruvbpdgrxlzyckwtfqjonsxe
mbruqapoghxlzyckwtvqjonsie
mbouhapdghmlzyckwtfqjonsie
mbruvapjghxidyckwtfqjonsie
mbsuvapkghxlkyckwtfqjonsie
mbruvlpdghxlzycrwtfqjonsis
mcrueapdghxlzyckwtfqjynsie
muruvapngbxlzyckwtfqjonsie
mbruvapdghxlzycawtfyjojsie
mbruvbpdghxczyjkwtfqjonsie
ybduvapdghxnzyckwtfqjonsie
mbruvbpdghxlzyckwtfbjousie
mbouvapdghxlzycbwtfqponsie
mbruvaedghplzycgwtfqjonsie
mbrhvapdghxlzyckytfqjgnsie
mbruvapdqbxleyckwtfqjonsie
mbruvapddhhldyckwtfqjonsie
mbruvapdghxlwrckwtfqjondie
mbruvapdmhxlzyckwtfqkonsve
xbbuvapdghxlzyckwtfkjonsie
mbruvapdghxlzyckwcfqjunkie
mbruvapdghxlzyckwtfqxonfib
mbrtvapkghxlzyckwtfqeonsie
mbruvazdghxldymkwtfqjonsie
kbruvapddhxlzfckwtfqjonsie
mbouvapdghxlpyckwtfqjoosie
mbauvapdghxlzyckwtfqjszsie
mbruvapdghtlzyckntfqtonsie
mbruvipdggxlzbckwtfqjonsie
mbruqapdghrlzyckwtfqjznsie
myruvacdghxlzyckwifqjonsie
mbruvapdghxlzuckwtfkjocsie
mwjuvapdghxlzyckwtfqjonsxe
mbruvapxghxlzickwtfqjobsie
mbrupapdghxtlyckwtfqjonsie
meruvapdjjxlzyckwtfqjonsie
mbruvkodghxlzyckwofqjonsie
mbruvapdgexlzyckwtgkjonsie
mbruvapwghxlzyckwtcqjonsiw
mbruvapdghxlzykkwtfqtoxsie
mbruvapdahxlzycgwtfwjonsie
mbruvapdgwxlhyckhtfqjonsie
mbruvapbghxlzycbhmfqjonsie
mbruvapdghxvzyzkwtfqjonsin
mbrcvapdqhxlzyckwyfqjonsie
zbruvaxdghxlzyckwgfqjonsie
mtruvapdghxlilckwtfqjonsie
bbruvapdghxlzyckwtfmjonsxe
mbruvajdghxlzyckwtfqfwnsie
mbruvapdgkxlzyckwtfqionpie
rbruvapdghxlryckwdfqjonsie
mbruvandghxlzyckwmfvjonsie
mbruvahdghxlzeckwtfqjonsme
mbruvnpcghxlzyckwtfqjobsie
mbruvapdghqlzyckwtfbjonsiy
mbruvavdghxlzyckwufqjodsie
mbruvapdghxlzyckwtfzmovsie
mbruvlpdghxuzyckwtfqjoesie
mbruvopdghxlzycwwtfqjansie
obruvapdghglzybkwtfqjonsie
mbpuvlpdghxlcyckwtfqjonsie
mbruvaidghxlzyckwtfmjonoie
mbruvapdihxzzyckwtfqjonsiy
mbquvapdghxlzyckwtfqconsme
mbruvapdghslzyckqtfqjojsie
mbrzdapdghxmzyckwtfqjonsie
mwruvapdghxozyckwtfqjonsxe
muruvapdgfxlzyckwtfqjojsie
wtruvapdghxlzyckvtfqjonsie
mbruvapdghxlzyckysfqjxnsie
mbruvrpdghxczyckktfqjonsie
mbquvapdghxlryckwtfqjonsne
mbruvapdghflzycvwtfqjpnsie
mbruvapughclzyckwtfqjonsin
mbrhvapdghxlpyckwtfqjonsre
mbruvapdgtxlzyckwtfqjoosit
mbrupapnghxhzyckwtfqjonsie
mmvuvapdvhxlzyckwtfqjonsie
mbruvaptghxlzyckwtfqjotsse
mgruvapvghxlzyckwtfqjonsix
mbrupapdghxszyckwtfqjunsie
mbruvkpdghelzyckwtfqjpnsie
mbruvrrdghjlzyckwtfqjonsie
mbruvapdghnlzyckwtfkjonsze
mbruvwpdghxlzyckwtfqhoysie
mbrsvapdfhxlzyckwtfqjobsie
mbruvapdgexezymkwtfqjonsie
ybruvapdghxlzyckwtfqxonsiw
mrruvapdghxdzyckwtfqjossie
mbruvapdghtlzyckwtfqconsiu
mbrpvapdghxlzlckwpfqjonsie
mbruvjpdghslzyckwtfqjjnsie
mhruvapoghxlzyckwtfvjonsie
mbrubqpdghvlzyckwtfqjonsie
mbruvapdghxlzackwtfqconsiw
mbruvapdgnxlzkckwtfqjdnsie
mbrudapgghelzyckwtfqjonsie
mbruvapdghxlzlakwbfqjonsie
mbpuvapdghxlzyckwtuqjonjie
abruvapdghxlzykkwtfqjonzie
mbrupupdghxlsyckwtfqjonsie
mbrsvupdghxlzyckwtfqjonkie
mxruvgpdghxllyckwtfqjonsie
mbrnvapdghxlzycbwtfqfonsie
mbrbxapdghxlzyckttfqjonsie
mbnuvapdghxlzyxkwtmqjonsie
mbrfvapdghjlzickwtfqjonsie
mbhuvupdghxlzyxkwtfqjonsie
mbrcvapdghxluyckwtfqjznsie
mbruvapdghxlzyckwofqjoxsiz
mbrevapdghxloyckwtfqjonnie
mbruvipdghnlzyckwtfqjopsie
mbxxvaptghxlzyckwtfqjonsie
mbruvcpdghxlztckwtjqjonsie
mqruvlpdghxlzyckotfqjonsie
mbruvapdgqxlzyckwtfqjpvsie
mbruvapdgvxlzyjkwtfqjbnsie
mbruvapdghxlgyckwtfqcocsie
mbruvapdghxkwyckwtfqjoqsie
mbrgvavdghxlzyckwxfqjonsie
qbruqapdgvxlzyckwtfqjonsie
mbauvapdghxlzgckwtfqjunsie
mbruvapdgdxluyckwtfqjoosie
mbruvapdghxlzykkwtfqwobsie
mbruvapdghxlzhcnwtfqjonqie
mbruvapdghxlzycbhmfqjonsie
mbruvapdghxluyczwtfqjontie
mbruvapnghxlzyckwnfqjonbie
moruvapdghxlzcckwtfqponsie
mbruvapfgxxlzyckwtfqjunsie
mbruvapdghxlryckvtfejonsie
mbrzvapdghxlzvcbwtfqjonsie
mbruvapdgqxlzyckwcfqjonsce
abruvupdrhxlzyckwtfqjonsie
mbrubaptghxlzyckwtfqjondie
mgruvapdgpxlzyckwtfijonsie
mbruvapdghxczlckwtfujonsie
mbruvapdgmmlzyckwtfqjonsir
mbruvapdhhxltyckwtfdjonsie
mbruvapdghxlzyckwtfdjjnste
mbrdvzpdghxlcyckwtfqjonsie
mbruvapdghxlzyckwtnqbonsim
mbrovapdghxlzyckwtfpjousie
mymuvapdghxlzyjkwtfqjonsie
mbpuvapdghxlzyckwtfljcnsie
mbrxvapdghxlzyclwtfqjonpie
mbrueapdghxlzyckwtfqjopsia
mbruvapdghxlzycdwtfqjbfsie
tbruvavdghxlzyckwtmqjonsie
mbduvapdghxlzyckwrfqjrnsie
mkrsvapughxlzyckwtfqjonsie
mbruvapdghylzyckwtfqtolsie
mgruvapdglxldyckwtfqjonsie
mbrunapdghclzyckwtfqjonsiy
mbruvapdgrxlxyckwtfgjonsie
mbruvapdghxpzbckftfqjonsie
mbruvcpdghxyzyckotfqjonsie
mbruvapdghxlsyckwtfqcqnsie
mbruvapdghxlzzckwtfqjonskf
mbruvppdghxlzfckwtfqjgnsie
mbhuvapdghxlzytkwtfqjonoie
mbruvapdghxlzvrkwtfqjjnsie
mbmuvapdghxuzyckwtfqjonsze
mbruvapdghnlzycnwtfqjonsil
mbruvapdgholzyckitfqjonsia
mbruxapdghxlmyckwtfqbonsie
mbauvapdgholzyckwtfqjolsie
mbruvapdghxlzyckwtfqjotslq
dbrutapdghxlzyckwtfqjonsiv
mbruvapdzhxlyyckwtfbjonsie
mmruaapsghxlzyckwtfqjonsie
mbruvaldgqxqzyckwtfqjonsie
mbruvaodghxdzyjkwtfqjonsie
mbrcmatdghxlzyckwtfqjonsie
mbrqvapdgtxlzycewtfqjonsie
mjruvapdghzlzyckwtfqjonrie
mbruvapdghxopcckwtfqjonsie
mbruvapdghxszycwwtfqjoqsie
mbruvapdgoxezyckwtjqjonsie

View File

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AoC2018.Solutions
{
public class Day2Solution: Solution
{
public override string Title => "Inventory Management System";
public override int Day => 2;
public override void Run()
{
string[] input = File.ReadAllLines(Path.Combine("Input", "Day2Input.txt"));
Console.WriteLine($"Part 1: {CalculatePart1(input)}");
Console.WriteLine($"Part 2: {CalculatePart2(input)}");
}
private int CalculatePart1(string[] input)
{
int value1 = 0, value2 = 0;
foreach (var s in input)
{
bool two = false, three = false;
var result = s.GroupBy(c => c).Select(c => new { Char = c.Key, Count = c.Count() });
foreach (var x in result)
{
if (x.Count == 2)
two = true;
else if (x.Count == 3)
three = true;
}
if (two) value1++;
if (three) value2++;
}
return value1 * value2;
}
private string CalculatePart2(string[] input)
{
string result = string.Empty;
for (int i = 0; i < input.Length; i++)
{
for (int j = 0; j < input.Length; j++)
{
var commonChars = CommonChars(input[i], input[j]).ToArray();
if (Math.Abs(input[j].Length - commonChars.Length) == 1)
return new string(commonChars);
}
}
return result;
}
private List<char> CommonChars(string left, string right)
{
List<char> identicalList = new List<char>(left.Length);
for(int i = 0; i < left.Length; i++)
if (left[i] == right[i])
identicalList.Add(left[i]);
return identicalList;
}
}
}