2016 day 5
This commit is contained in:
parent
a2e44cceb0
commit
988a13324d
|
@ -10,6 +10,7 @@ public class Test2016
|
|||
[DataRow(typeof(Day02), "76792", "A7AC3")]
|
||||
[DataRow(typeof(Day03), "993", "1849")]
|
||||
[DataRow(typeof(Day04), "361724", "482")]
|
||||
[DataRow(typeof(Day05), "F77A0E6E", "999828EC")]
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
Common.CheckDay(dayType, part1, part2);
|
||||
|
@ -17,6 +18,7 @@ public class Test2016
|
|||
|
||||
[DataTestMethod]
|
||||
[DataRow(typeof(Day02), "1985", "5DB3")]
|
||||
[DataRow(typeof(Day05), "18F47A30", "05ACE8E3")]
|
||||
public void CheckTestInputs(Type dayType, string part1, string part2)
|
||||
{
|
||||
Common.CheckDay(dayType, part1, part2, true);
|
||||
|
|
|
@ -1,15 +1,59 @@
|
|||
using System.Security.Cryptography;
|
||||
|
||||
namespace AOC2016;
|
||||
|
||||
/// <summary>
|
||||
/// Day 5: <a href="https://adventofcode.com/2016/day/5"/>
|
||||
/// </summary>
|
||||
public sealed class Day05() : Day(2016, 5, "Puzzle Name")
|
||||
public sealed class Day05() : Day(2016, 5, "How About a Nice Game of Chess?")
|
||||
{
|
||||
public override void ProcessInput()
|
||||
{
|
||||
}
|
||||
|
||||
public override object Part1() => "";
|
||||
public override object Part1()
|
||||
{
|
||||
var s = Input.First();
|
||||
var answer = new char[8];
|
||||
var index = 0;
|
||||
|
||||
public override object Part2() => "";
|
||||
}
|
||||
for (var i = 0; i < answer.Length; i++)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var hash = BitConverter.ToString(MD5.HashData(Encoding.ASCII.GetBytes(s + index++))).Replace("-", "");
|
||||
if (hash.StartsWith("00000"))
|
||||
{
|
||||
answer[i] = hash[5];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new string(answer);
|
||||
}
|
||||
|
||||
public override object Part2()
|
||||
{
|
||||
var s = Input.First();
|
||||
var answer = new char[8];
|
||||
var index = 0;
|
||||
var found = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var hash = BitConverter.ToString(MD5.HashData(Encoding.ASCII.GetBytes(s + index++))).Replace("-", "");
|
||||
if (hash.StartsWith("00000"))
|
||||
{
|
||||
var target = hash[5] - '0';
|
||||
if (target is < 8 and >= 0 && answer[target] == 0)
|
||||
{
|
||||
answer[target] = hash[6];
|
||||
if (++found == 8) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new string(answer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
abc
|
Loading…
Reference in New Issue