day 3 part 1
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
437ad3ecfa
commit
15cf1a6a56
|
@ -6,6 +6,7 @@ public class DayTests
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
[DataRow(typeof(Day01), "1616", "1645")]
|
[DataRow(typeof(Day01), "1616", "1645")]
|
||||||
[DataRow(typeof(Day02), "2272262", "2134882034")]
|
[DataRow(typeof(Day02), "2272262", "2134882034")]
|
||||||
|
[DataRow(typeof(Day03), "3009600", "")]
|
||||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||||
{
|
{
|
||||||
var s = Stopwatch.StartNew();
|
var s = Stopwatch.StartNew();
|
||||||
|
@ -38,6 +39,7 @@ public class DayTests
|
||||||
[DataTestMethod]
|
[DataTestMethod]
|
||||||
[DataRow(typeof(Day01), "7", "5")]
|
[DataRow(typeof(Day01), "7", "5")]
|
||||||
[DataRow(typeof(Day02), "150", "900")]
|
[DataRow(typeof(Day02), "150", "900")]
|
||||||
|
[DataRow(typeof(Day03), "198", "230")]
|
||||||
public void CheckTestInputs(Type dayType, string part1, string part2)
|
public void CheckTestInputs(Type dayType, string part1, string part2)
|
||||||
{
|
{
|
||||||
Day.UseTestInput = true;
|
Day.UseTestInput = true;
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
namespace aoc2021;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Day 3: <see href="https://adventofcode.com/2021/day/3"/>
|
||||||
|
/// </summary>
|
||||||
|
public sealed class Day03 : Day
|
||||||
|
{
|
||||||
|
private readonly List<string> _report;
|
||||||
|
|
||||||
|
public Day03() : base(3, "Binary Diagnostic")
|
||||||
|
{
|
||||||
|
_report = Input.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Part1()
|
||||||
|
{
|
||||||
|
var l = _report.Count / 2;
|
||||||
|
var g = new StringBuilder();
|
||||||
|
var e = new StringBuilder();
|
||||||
|
|
||||||
|
foreach (var i in Enumerable.Range(0, _report[0].Length))
|
||||||
|
{
|
||||||
|
var ones = _report.Select(r => r[i]).Count(c => c == '1');
|
||||||
|
g.Append(ones > l ? '1' : '0');
|
||||||
|
e.Append(ones > l ? '0' : '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
var gamma = Convert.ToInt32(g.ToString(), 2);
|
||||||
|
var epsilon = Convert.ToInt32(e.ToString(), 2);
|
||||||
|
|
||||||
|
return $"{gamma * epsilon}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Part2()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,12 @@
|
||||||
|
00100
|
||||||
|
11110
|
||||||
|
10110
|
||||||
|
10111
|
||||||
|
10101
|
||||||
|
01111
|
||||||
|
00111
|
||||||
|
11100
|
||||||
|
10000
|
||||||
|
11001
|
||||||
|
00010
|
||||||
|
01010
|
Loading…
Reference in New Issue