mirror of
https://github.com/ckaczor/Advent2019.git
synced 2026-01-13 17:22:15 -05:00
Day 8 - Part 1
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
50
Day8/Day8.cs
Normal 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
1
Day8/input.txt
Normal file
File diff suppressed because one or more lines are too long
@@ -10,7 +10,8 @@
|
||||
//Day4.Execute();
|
||||
//Day5.Execute();
|
||||
//Day6.Execute();
|
||||
Day7.Execute();
|
||||
//Day7.Execute();
|
||||
Day8.Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user