Day 8 - Part 1

This commit is contained in:
2019-12-10 18:19:47 -05:00
parent e2ae232d03
commit 99a7ca3299
5 changed files with 58 additions and 2 deletions

View File

@@ -25,6 +25,9 @@
<None Update="Day6\test-input.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Day8\input.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -5,4 +5,5 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day4/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day5/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day6/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day7/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day7/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=day8/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

50
Day8/Day8.cs Normal file
View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Advent
{
public static class Day8
{
public static void Execute()
{
var lines = File.ReadAllLines(@".\Day8\input.txt");
var data = lines[0].ToCharArray();
var index = 0;
var minimumZeroCount = int.MaxValue;
var minimumZeroLayer = 0;
var layers = new List<char[]>();
while (index < data.Length)
{
var layer = data[index..(index + 25 * 6)];
layers.Add(layer);
index += (25 * 6);
}
var layerIndex = 0;
foreach (var layer in layers)
{
var currentZeroCount = layer.Count(c => c == '0');
if (currentZeroCount < minimumZeroCount)
{
minimumZeroCount = currentZeroCount;
minimumZeroLayer = layerIndex;
}
layerIndex++;
}
Console.WriteLine(layers[minimumZeroLayer].Count(c => c == '1') * layers[minimumZeroLayer].Count(c => c == '2'));
}
}
}

1
Day8/input.txt Normal file

File diff suppressed because one or more lines are too long

View File

@@ -10,7 +10,8 @@
//Day4.Execute();
//Day5.Execute();
//Day6.Execute();
Day7.Execute();
//Day7.Execute();
Day8.Execute();
}
}
}