run code formatter
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
ca34fdae9e
commit
9904a454a0
|
@ -9,11 +9,13 @@ namespace aoc2020
|
|||
/// </summary>
|
||||
public sealed class Day14 : Day
|
||||
{
|
||||
private readonly Dictionary<ulong, ulong> _writesDict;
|
||||
private readonly Dictionary<ulong, ulong> _writes;
|
||||
private readonly Dictionary<ulong, ulong> _writes2;
|
||||
|
||||
public Day14() : base(14)
|
||||
{
|
||||
_writesDict = new Dictionary<ulong, ulong>();
|
||||
_writes = new Dictionary<ulong, ulong>();
|
||||
_writes2 = new Dictionary<ulong, ulong>();
|
||||
}
|
||||
|
||||
public override string Part1()
|
||||
|
@ -21,22 +23,14 @@ namespace aoc2020
|
|||
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 if (str[35 - i] == '1') bits |= (ulong) 1 << i;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -46,11 +40,10 @@ namespace aoc2020
|
|||
.Select(ulong.Parse)
|
||||
.ToArray();
|
||||
|
||||
_writesDict[spl[0]] = (spl[1] & mask) | bits;
|
||||
_writes[spl[0]] = (spl[1] & mask) | bits;
|
||||
}
|
||||
}
|
||||
|
||||
return $"{_writesDict.Aggregate<KeyValuePair<ulong, ulong>, ulong>(0, (current, w) => current + w.Value)}";
|
||||
return $"{_writes.Aggregate<KeyValuePair<ulong, ulong>, ulong>(0, (current, w) => current + w.Value)}";
|
||||
}
|
||||
|
||||
public override string Part2()
|
||||
|
@ -58,4 +51,4 @@ namespace aoc2020
|
|||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue