day 14 part 1
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
97b58586dd
commit
ca34fdae9e
|
@ -21,6 +21,7 @@ namespace aoc2020.test
|
|||
[DataRow(typeof(Day11), "2303", "2057")]
|
||||
[DataRow(typeof(Day12), "1710", "62045")]
|
||||
[DataRow(typeof(Day13), "171", "539746751134958")]
|
||||
[DataRow(typeof(Day14), "17481577045893", "")]
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
// create day instance
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace aoc2020
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -5,13 +9,48 @@ namespace aoc2020
|
|||
/// </summary>
|
||||
public sealed class Day14 : Day
|
||||
{
|
||||
private readonly Dictionary<ulong, ulong> _writesDict;
|
||||
|
||||
public Day14() : base(14)
|
||||
{
|
||||
_writesDict = new Dictionary<ulong, ulong>();
|
||||
}
|
||||
|
||||
public override string Part1()
|
||||
{
|
||||
return "";
|
||||
ulong mask = 0, bits = 0;
|
||||
|
||||
foreach (var line in Input)
|
||||
{
|
||||
if (line.StartsWith("mask = "))
|
||||
{
|
||||
var str = line.Split("mask = ", 2)[1];
|
||||
mask = bits = 0;
|
||||
for (var i = 35; i >= 0; --i)
|
||||
{
|
||||
if (str[35 - i] == 'X')
|
||||
{
|
||||
mask |= (ulong) 1 << i;
|
||||
}
|
||||
else if (str[35 - i] == '1')
|
||||
{
|
||||
bits |= (ulong) 1 << i;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var spl = line.Split(new[] {'[', ']', '='},
|
||||
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Skip(1)
|
||||
.Select(ulong.Parse)
|
||||
.ToArray();
|
||||
|
||||
_writesDict[spl[0]] = (spl[1] & mask) | bits;
|
||||
}
|
||||
}
|
||||
|
||||
return $"{_writesDict.Aggregate<KeyValuePair<ulong, ulong>, ulong>(0, (current, w) => current + w.Value)}";
|
||||
}
|
||||
|
||||
public override string Part2()
|
||||
|
|
Loading…
Reference in New Issue