day 3 part 2
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Ben Harris 2021-12-03 11:59:54 -05:00
parent 15cf1a6a56
commit 7baf9b8bb5
2 changed files with 23 additions and 2 deletions

View File

@ -6,7 +6,7 @@ public class DayTests
[DataTestMethod]
[DataRow(typeof(Day01), "1616", "1645")]
[DataRow(typeof(Day02), "2272262", "2134882034")]
[DataRow(typeof(Day03), "3009600", "")]
[DataRow(typeof(Day03), "3009600", "6940518")]
public void CheckAllDays(Type dayType, string part1, string part2)
{
var s = Stopwatch.StartNew();

View File

@ -33,6 +33,27 @@ public sealed class Day03 : Day
public override string Part2()
{
return "";
var o = _report;
var c = _report;
var i = 0;
while (o.Count > 1)
{
var most = o.Count(r => r[i] == '1') >= o.Count / 2.0 ? '1' : '0';
o = o.Where(r => r[i] == most).ToList();
i++;
}
var o2 = Convert.ToInt64(o.Single(), 2);
i = 0;
while (c.Count > 1)
{
var most = c.Count(r => r[i] == '1') >= c.Count / 2.0 ? '0' : '1';
c = c.Where(r => r[i] == most).ToList();
i++;
}
var co2 = Convert.ToInt64(c.Single(), 2);
return $"{o2 * co2}";
}
}