2015 day 4
This commit is contained in:
parent
c81fe490e5
commit
ade1148cc0
|
@ -9,6 +9,7 @@ public class Test2015
|
||||||
[DataRow(typeof(Day01), "232", "1783")]
|
[DataRow(typeof(Day01), "232", "1783")]
|
||||||
[DataRow(typeof(Day02),"1586300", "3737498")]
|
[DataRow(typeof(Day02),"1586300", "3737498")]
|
||||||
[DataRow(typeof(Day03), "2081", "2341")]
|
[DataRow(typeof(Day03), "2081", "2341")]
|
||||||
|
// [DataRow(typeof(Day04), "346386", "9958218")]
|
||||||
public void TestAllDays(Type dayType, string part1, string part2)
|
public void TestAllDays(Type dayType, string part1, string part2)
|
||||||
{
|
{
|
||||||
Common.CheckDay(dayType, part1, part2);
|
Common.CheckDay(dayType, part1, part2);
|
||||||
|
@ -18,6 +19,7 @@ public class Test2015
|
||||||
[DataRow(typeof(Day01), "-1", "5")]
|
[DataRow(typeof(Day01), "-1", "5")]
|
||||||
[DataRow(typeof(Day02), "58", "34")]
|
[DataRow(typeof(Day02), "58", "34")]
|
||||||
[DataRow(typeof(Day03), "2", "11")]
|
[DataRow(typeof(Day03), "2", "11")]
|
||||||
|
// [DataRow(typeof(Day04), "609043", "6742839")]
|
||||||
public void CheckTestInputs(Type dayType, string part1, string part2)
|
public void CheckTestInputs(Type dayType, string part1, string part2)
|
||||||
{
|
{
|
||||||
Day.UseTestInput = true;
|
Day.UseTestInput = true;
|
||||||
|
|
|
@ -1,15 +1,44 @@
|
||||||
namespace AOC2015;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
namespace AOC2015;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Day 4: <see href="https://adventofcode.com/2015/day/4"/>
|
/// Day 4: <see href="https://adventofcode.com/2015/day/4"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Day04 : Day
|
public sealed class Day04 : Day
|
||||||
{
|
{
|
||||||
|
private readonly string _key;
|
||||||
|
|
||||||
public Day04() : base(2015, 4, "Puzzle Name")
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
abcdef
|
Loading…
Reference in New Issue