day 8
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
270cac64a4
commit
cd816151aa
|
@ -0,0 +1,39 @@
|
|||
using aoc2019.lib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace aoc2019
|
||||
{
|
||||
internal class Day8 : Day
|
||||
{
|
||||
public override int DayNumber => 8;
|
||||
|
||||
private readonly List<List<char>> photo;
|
||||
public Day8()
|
||||
{
|
||||
photo = Input.First().Chunk(25 * 6).Select(s => s.ToList()).ToList();
|
||||
}
|
||||
|
||||
public override string Part1()
|
||||
{
|
||||
var l = photo.OrderBy(layer => layer.Count(pixel => pixel == '0')).First();
|
||||
return $"{l.Count(p => p == '1') * l.Count(p => p == '2')}";
|
||||
}
|
||||
|
||||
public override string Part2()
|
||||
{
|
||||
return Enumerable.Range(0, 25 * 6)
|
||||
.Select(p => Enumerable.Range(0, photo.Count)
|
||||
.Select(l => photo[l][p])
|
||||
.Aggregate('2', (acc, next) =>
|
||||
acc != '2' ? acc : next == '0' ? ' ' : next
|
||||
)
|
||||
)
|
||||
.ToDelimitedString()
|
||||
.Chunk(25)
|
||||
.ToDelimitedString(Environment.NewLine)
|
||||
.Replace('1', 'x');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,6 +27,9 @@
|
|||
<None Update="input\day7.in">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="input\day8.in">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -11,5 +11,16 @@ namespace aoc2019.lib
|
|||
if (list.Count() == 1) return new[] { list };
|
||||
return list.SelectMany(t => Permute(list.Where(x => !x.Equals(t))), (v, p) => p.Prepend(v));
|
||||
}
|
||||
|
||||
public static IEnumerable<string> Chunk(this string str, int chunkSize)
|
||||
{
|
||||
for (int i = 0; i < str.Length; i += chunkSize)
|
||||
yield return str.Substring(i, chunkSize);
|
||||
}
|
||||
|
||||
public static string ToDelimitedString<T>(this IEnumerable<T> enumerable, string delimiter = "")
|
||||
{
|
||||
return string.Join(delimiter, enumerable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue