ben
/
aoc
1
0
Fork 0

2015 day 4

This commit is contained in:
Ben Harris 2022-11-11 16:31:34 -05:00
parent c81fe490e5
commit ade1148cc0
3 changed files with 35 additions and 3 deletions

View File

@ -9,6 +9,7 @@ public class Test2015
[DataRow(typeof(Day01), "232", "1783")]
[DataRow(typeof(Day02),"1586300", "3737498")]
[DataRow(typeof(Day03), "2081", "2341")]
// [DataRow(typeof(Day04), "346386", "9958218")]
public void TestAllDays(Type dayType, string part1, string part2)
{
Common.CheckDay(dayType, part1, part2);
@ -18,6 +19,7 @@ public class Test2015
[DataRow(typeof(Day01), "-1", "5")]
[DataRow(typeof(Day02), "58", "34")]
[DataRow(typeof(Day03), "2", "11")]
// [DataRow(typeof(Day04), "609043", "6742839")]
public void CheckTestInputs(Type dayType, string part1, string part2)
{
Day.UseTestInput = true;

View File

@ -1,15 +1,44 @@
namespace AOC2015;
using System.Security.Cryptography;
namespace AOC2015;
/// <summary>
/// Day 4: <see href="https://adventofcode.com/2015/day/4"/>
/// </summary>
public sealed class Day04 : Day
{
private readonly string _key;
public Day04() : base(2015, 4, "Puzzle Name")
{
_key = Input.First();
}
public override object Part1() => "";
public override object Part1()
{
var md5 = MD5.Create();
var counter = 0;
public override object Part2() => "";
while (true)
{
var hash = md5.ComputeHash(Encoding.ASCII.GetBytes(_key + counter));
if (BitConverter.ToString(hash).Replace("-", "").StartsWith("00000"))
return counter;
counter++;
}
}
public override object Part2()
{
var md5 = MD5.Create();
var counter = 0;
while (true)
{
var hash = md5.ComputeHash(Encoding.ASCII.GetBytes(_key + counter));
if (BitConverter.ToString(hash).Replace("-", "").StartsWith("000000"))
return counter;
counter++;
}
}
}

View File

@ -0,0 +1 @@
abcdef